Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find JDBC type '2003' in PostgreSQL column type #6408

Closed
1ssqq1lxr opened this issue Jul 23, 2020 · 17 comments · Fixed by #6474
Closed

Cannot find JDBC type '2003' in PostgreSQL column type #6408

1ssqq1lxr opened this issue Jul 23, 2020 · 17 comments · Fixed by #6474

Comments

@1ssqq1lxr
Copy link

SELECT d.oid, d.datname AS databasename, d.datacl, pg_get_userbyid(d.datdba) AS databaseowner, d.datcollate, d.datctype, shobj_description(d.oid, 'pg_database') AS description, d.datconnlimit, t.spcname, d.encoding, pg_encoding_to_char(d.encoding) AS encodingname FROM pg_database d LEFT JOIN pg_tablespace t ON d.dattablespace = t.oid ::: DataSources: initds_master
[ERROR] 02:51:14.421 [pool-4-thread-1] o.a.s.s.f.c.CommandExecutorTask - Exception occur:
java.lang.IllegalArgumentException: Cannot find JDBC type '2003' in PostgreSQL column type

@jingshanglu
Copy link
Contributor

@1ssqq1lxr Change sql to "SELECT d.oid, d.datname AS databasename, d.datacl, pg_get_userbyid(d.datdba) AS databaseowner, d.datcollate, d.datctype, shobj_description(d.oid, 'pg_database') AS description, d.datconnlimit, t.spcname, d.encoding, pg_encoding_to_char(d.encoding) AS encodingname FROM pg_database d LEFT JOIN pg_tablespace t ON d.dattablespace = t.oid", is it ok?

@1ssqq1lxr
Copy link
Author

1ssqq1lxr commented Jul 23, 2020 via email

@jingshanglu
Copy link
Contributor

@1ssqq1lxr Ok, could the origin sql directly run on pg server?

@1ssqq1lxr
Copy link
Author

1ssqq1lxr commented Jul 23, 2020 via email

@jingshanglu
Copy link
Contributor

@1ssqq1lxr Maybe it is the parser problem. I'll check it.

@jingshanglu
Copy link
Contributor

@1ssqq1lxr What's the meaning of "::: DataSources: initds_master", I didn't find the ':::' operator in PG.

@1ssqq1lxr
Copy link
Author

@ 1ssqq1lxr “ ::: DataSources:initds_master”是什么意思,我在PG中找不到':::'运算符。

Complete SQL: SELECT d.oid, d.datname AS databasename, d.datacl, d.datistemplate, d.datallowconn, pg_get_userbyid(d.datdba) AS databaseowner, d.datcollate, d.datctype, shobj_description(d.oid, 'pg_database') AS description, d.datconnlimit, t.spcname, d.encoding, pg_encoding_to_char(d.encoding) AS encodingname FROM pg_database d LEFT JOIN pg_tablespace t ON d.dattablespace = t.oid

Do you mean there is something wrong with my data source configuration? I have switched multiple PostgreSQL versions and still have this problem。
config-master_slave.yaml:
schemaName: 91nami
dataSources:
91ds_master:
url: jdbc:postgresql://192.168.0.6:9527/mycat?serverTimezone=UTC+8&useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowEncodingChanges=true
username: postgres
password: sonic333
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 65
91ds_slave0:
url: jdbc:postgresql://192.168.0.229:9527/mycat?serverTimezone=UTC+8&useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowEncodingChanges=true
username: postgres
password: sonic333
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 65

masterSlaveRule:
name: 91ds_ms
masterDataSourceName: 91ds_master
slaveDataSourceNames:
- 91ds_slave0

server.yaml:
authentication:
users:
postgresuser:
password: sonic333
authorizedSchemas: 91nami
props:
sql.show: true
acceptor.size: 16
proxy.transaction.type: LOCAL
proxy.opentracing.enabled: false
check.table.metadata.enabled: true

@jingshanglu
Copy link
Contributor

@1ssqq1lxr Origin sql is "SELECT d.oid, d.datname AS databasename, d.datacl, pg_get_userbyid(d.datdba) AS databaseowner, d.datcollate, d.datctype, shobj_description(d.oid, 'pg_database') AS description, d.datconnlimit, t.spcname, d.encoding, pg_encoding_to_char(d.encoding) AS encodingname FROM pg_database d LEFT JOIN pg_tablespace t ON d.dattablespace = t.oid ::: DataSources: initds_master" , right?

@1ssqq1lxr
Copy link
Author

@1ssqq1lxr Origin sql is "SELECT d.oid, d.datname AS databasename, d.datacl, pg_get_userbyid(d.datdba) AS databaseowner, d.datcollate, d.datctype, shobj_description(d.oid, 'pg_database') AS description, d.datconnlimit, t.spcname, d.encoding, pg_encoding_to_char(d.encoding) AS encodingname FROM pg_database d LEFT JOIN pg_tablespace t ON d.dattablespace = t.oid ::: DataSources: initds_master" , right?

origin sql is "SELECT d.oid, d.datname AS databasename, d.datacl, pg_get_userbyid(d.datdba) AS databaseowner, d.datcollate, d.datctype, shobj_description(d.oid, 'pg_database') AS description, d.datconnlimit, t.spcname, d.encoding, pg_encoding_to_char(d.encoding) AS encodingname FROM pg_database d LEFT JOIN pg_tablespace t ON d.dattablespace = t.oid" "::: DataSources: initds_master" getdatasouce log ?

@jingshanglu
Copy link
Contributor

@1ssqq1lxr Ok, it is not parser problem and is the same to #3954

@kimmking
Copy link
Member

duplicated with #6396 #6232 #6132 #3954 #3591 #3104

@kimmking
Copy link
Member

kimmking commented Jul 23, 2020

And so it's a critical bug for PG users, we should raise priority 0 for this issue now.
@jingshanglu @tuohai666

@kimmking kimmking changed the title SELECT d.oid, d.datname AS databasename, d.datacl, pg_get_userbyid(d.datdba) AS databaseowner, d.datcollate, d.datctype, shobj_description(d.oid, 'pg_database') AS description, d.datconnlimit, t.spcname, d.encoding, pg_encoding_to_char(d.encoding) AS encodingname FROM pg_database d LEFT JOIN pg_tablespace t ON d.dattablespace = t.oid ::: DataSources: initds_master [ERROR] 02:51:14.421 [pool-4-thread-1] o.a.s.s.f.c.CommandExecutorTask - Exception occur: java.lang.IllegalArgumentException: Cannot find JDBC type '2003' in PostgreSQL column type PostgreSQL with Sharding: Cannot find JDBC type '2003' in PostgreSQL column type Jul 23, 2020
@kimmking kimmking changed the title PostgreSQL with Sharding: Cannot find JDBC type '2003' in PostgreSQL column type Cannot find JDBC type '2003' in PostgreSQL column type Jul 23, 2020
@kimmking kimmking added this to the 5.0.0 milestone Jul 23, 2020
@1ssqq1lxr
Copy link
Author

And so it's a critical bug for PG users, we should raise priority 0 for this issue now.
@jingshanglu @tuohai666

Thank you. Can you solve it quickly

@kimmking
Copy link
Member

kimmking commented Jul 23, 2020

And so it's a critical bug for PG users, we should raise priority 0 for this issue now.
@jingshanglu @tuohai666

Thank you. Can you solve it quickly

it will be fixed in 5.0.0
and if you need it now, I suggest you can fix it in your own fork.

@sandynz
Copy link
Contributor

sandynz commented Jul 24, 2020

Hi, I'd like try to solve it

@sandynz
Copy link
Contributor

sandynz commented Jul 26, 2020

I've prepared a demo and reproduced the error result.

After reading some code and debuging, java.sql.Types.ARRAY=2003, many types could be used as array and they have their own unique type oid, e.g. INT4_ARRAY=1007, INT8_ARRAY=1016, so jdbc array columnType(2003) is not enough to get exact array oid. There are 2 possible solutions for now:

1, Get resultSetMetaData from queryResponse.queryResults, use PostgreSQL's implementation PgResultSetMetaData, get field of column index via java reflection, then get type oid. The disadvantage is: a) direct dependency of postgresql jdbc driver, b) once the internal implementation of PostgreSQL jdbc driver changed, then it doesn't work.

2, Get resultSetMetaData from queryResponse.queryResults, use getColumnTypeName(column) method to get database specific type name (e.g. integer array is _int4), then translate it to type oid (e.g. 1007), PostgreSQL has the mapping definition.

I prefer solution 2, though it need more code.

sandynz added a commit to sandynz/shardingsphere that referenced this issue Jul 28, 2020
tuohai666 pushed a commit that referenced this issue Jul 29, 2020
…6474)

* Support PostgreSQL array type (#6408)

* Support PostgreSQL array type, unit test (#6408)

* Support PostgreSQL array type, follow review suggestion (#6408)
@bobqian1007
Copy link

seems meet this problem again on shardingsphere proxy:5.4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment