shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

ColumnMetaDataLoader load error and proxy cannot start success

Open zero2hj opened this issue 6 years ago • 2 comments

Bug Report

java.sql.SQLException: Column 'DBNAME' not found.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
	at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1078)
	at com.zaxxer.hikari.pool.HikariProxyResultSet.findColumn(HikariProxyResultSet.java)
	at org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaDataLoader.load(ColumnMetaDataLoader.java:78)
	at org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaDataLoader.load(TableMetaDataLoader.java:46)
	at org.apache.shardingsphere.core.metadata.ShardingMetaDataLoader.load(ShardingMetaDataLoader.java:83)
	at org.apache.shardingsphere.core.metadata.ShardingMetaDataLoader.loadShardingSchemaMetaData(ShardingMetaDataLoader.java:134)
	at org.apache.shardingsphere.core.metadata.ShardingMetaDataLoader.load(ShardingMetaDataLoader.java:125)
	at org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSchema.loadSchemaMetaData(ShardingSchema.java:179)
	at org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSchema.createMetaData(ShardingSchema.java:88)
	at org.apache.shardingsphere.shardingproxy.backend.schema.impl.ShardingSchema.<init>(ShardingSchema.java:79)
	at org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchemaFactory.newInstance(LogicSchemaFactory.java:56)
	at org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchemas.initSchemas(LogicSchemas.java:102)
	at org.apache.shardingsphere.shardingproxy.backend.schema.LogicSchemas.init(LogicSchemas.java:91)
	at org.apache.shardingsphere.shardingproxy.Bootstrap.startWithRegistryCenter(Bootstrap.java:138)
	at org.apache.shardingsphere.shardingproxy.Bootstrap.main(Bootstrap.java:87)

Which version of ShardingSphere did you use?

4.1.1

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-Proxy

Expected behavior

Actual behavior

Reason analyze (If you can)

ColumnMetaDataLoader load error because JDBC API DatabaseMetaData getTables consider _ as a wildcard symbol and will find all tables match the table pattern. we have two tables like this a_b_d and a_bcd. when load 1st table's column, it also loads the second table's column, then throw column xxx not found.

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

just create two tables match the pattern above and they should have a different columns. Then bootstrap the sharding-proxy

Example codes for reproduce this issue (such as a github link).

zero2hj avatar Sep 07 '20 03:09 zero2hj

You are right.

    /**
     * Retrieves a description of the tables available in the given catalog.
     * Only table descriptions matching the catalog, schema, table
     * name and type criteria are returned.  They are ordered by
     * <code>TABLE_TYPE</code>, <code>TABLE_CAT</code>,
     * <code>TABLE_SCHEM</code> and <code>TABLE_NAME</code>.
     * <P>
     * Each table description has the following columns:
     *  <OL>
     *  <LI><B>TABLE_CAT</B> String {@code =>} table catalog (may be <code>null</code>)
     *  <LI><B>TABLE_SCHEM</B> String {@code =>} table schema (may be <code>null</code>)
     *  <LI><B>TABLE_NAME</B> String {@code =>} table name
     *  <LI><B>TABLE_TYPE</B> String {@code =>} table type.  Typical types are "TABLE",
     *                  "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
     *                  "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
     *  <LI><B>REMARKS</B> String {@code =>} explanatory comment on the table
     *  <LI><B>TYPE_CAT</B> String {@code =>} the types catalog (may be <code>null</code>)
     *  <LI><B>TYPE_SCHEM</B> String {@code =>} the types schema (may be <code>null</code>)
     *  <LI><B>TYPE_NAME</B> String {@code =>} type name (may be <code>null</code>)
     *  <LI><B>SELF_REFERENCING_COL_NAME</B> String {@code =>} name of the designated
     *                  "identifier" column of a typed table (may be <code>null</code>)
     *  <LI><B>REF_GENERATION</B> String {@code =>} specifies how values in
     *                  SELF_REFERENCING_COL_NAME are created. Values are
     *                  "SYSTEM", "USER", "DERIVED". (may be <code>null</code>)
     *  </OL>
     *
     * <P><B>Note:</B> Some databases may not return information for
     * all tables.
     *
     * @param catalog a catalog name; must match the catalog name as it
     *        is stored in the database; "" retrieves those without a catalog;
     *        <code>null</code> means that the catalog name should not be used to narrow
     *        the search
     * @param schemaPattern a schema name pattern; must match the schema name
     *        as it is stored in the database; "" retrieves those without a schema;
     *        <code>null</code> means that the schema name should not be used to narrow
     *        the search
     * @param tableNamePattern a table name pattern; must match the
     *        table name as it is stored in the database
     * @param types a list of table types, which must be from the list of table types
     *         returned from {@link #getTableTypes},to include; <code>null</code> returns
     * all types
     * @return <code>ResultSet</code> - each row is a table description
     * @exception SQLException if a database access error occurs
     * @see #getSearchStringEscape
     */
    ResultSet getTables(String catalog, String schemaPattern,
                        String tableNamePattern, String types[]) throws SQLException;

kimmking avatar Sep 07 '20 07:09 kimmking

@chana71 hi,thanks, you can follow this #7330 will fix it。

yu199195 avatar Sep 08 '20 12:09 yu199195