apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.85k stars 6.72k forks source link

MySQLStatementParser throws NullPointerException #30283

Closed godojoe closed 2 months ago

godojoe commented 7 months ago

I am trying to get started with ShardingSphere-Proxy, running against MySQL. I have used the config from the User Manual. I am using IntelliJ DataGrip to successfully connect to the proxy, but cannot see my backend schemas. I would expect DataGrip to show me the tables residing on my MySQL instances, but I only see system tables. DataGrip reports this: Unknown column 'expression' in 'field list'. Unknown exception: Cannot invoke "org.antlr.v4.runtime.tree.TerminalNode.getText()" because the return value of "org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser$IdentifierContext.IDENTIFIER_()" is null. Table or viewrole_edgesdoes not exist. and 25 duplicate reports

The Proxy logs are filed with messages like this:

java.lang.NullPointerException: Cannot invoke "org.antlr.v4.runtime.tree.TerminalNode.getText()" because the return value of "org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser$IdentifierContext.IDENTIFIER_()" is null
2024-02-25 11:53:46     at org.apache.shardingsphere.sql.parser.mysql.visitor.statement.MySQLStatementVisitor.visitFunctionName(MySQLStatementVisitor.java:365)

My config: ShardingSphere-Proxy:5.4.1 MySql 8.3.0 driver under ext-lib/ : mysql-connector-java-8.0.28-8.3p2

server.yaml:

authority:
  users:
    - user: root@%
      password: root
    - user: sharding
      password: sharding

global.yaml:

sql-show: true
sqlParser:
  sqlStatementCache:
    initialCapacity: 2000
    maximumSize: 65535
  parseTreeCache:
    initialCapacity: 128
    maximumSize: 1024

transaction:
  defaultType: XA
  providerType: Atomikos

sqlTranslator:
  type:
  useOriginalSQLWhenTranslatingFailed:

sqlFederation:
  sqlFederationEnabled: true
  allQueryUseSQLFederation: false
  executionPlanCache:
    initialCapacity: 2000
    maximumSize: 65535

config-sharding:

schemaName: sharding_risk_db

dataSources:
  ds_0:
    url: jdbc:mysql://h2_risk-mysql0-1:3306/risk
    username: riskuser
    password: *
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  ds_1:
    url: jdbc:mysql://h2_risk-mysql1-1:3306/risk
    username: riskuser
    password: *
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  ds_2:
    url: jdbc:mysql://h2_risk-mysql2-1:3306/risk
    username: riskuser
    password: *
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
strongduanmu commented 7 months ago

Hi @godojoe, thank you for your feedback. This appears to be a parsing error, can you try debug to see what the original SQL is?

strongduanmu commented 7 months ago

Also, I noticed that you didn't configure any database rule. Is that what you expected?

godojoe commented 7 months ago

I cannot see the SQL in the shardingsphere logs, even though I have set sql-show: true in global.yaml. But I do see lots of errors such as this: java.sql.SQLException: 'information_schema.INNODB_TABLESTATS' is not VIEW, java.sql.SQLException: 'information_schema.INNODB_TRX' is not VIEW

And yes, I have not setup any database rule: I was hoping shardingsphere would simply broadcast my sql queries and union the results. (I am only performing SELECTs..). I just used the config from the latest release notes: https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-proxy/yaml-config/

github-actions[bot] commented 6 months ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

zzyReal666 commented 5 months ago

I had the same problem.

version: shardingphere-proxy 5.4.1 encrypt

encrypt-conf: I dont config any encrypt rules. Because this is just to test the proxy. image

problem:

  1. First time connect proxy use DataGrep,proxy got many error,such as : information_schema.INNODB_BUFFER_PAGE is not VIEW and information_schema.INNODB_BUFFER_PAGE_LRU is not VIEW etc. image
  2. DataGrip does not display real tables, but can query them,beacaus I had config - !SINGLE tables: - "*.*",before I config it,DataGrip can not find any single tables. image

3.DataGrip throws exception: image

strongduanmu commented 5 months ago

For question 2, you can read faq to solve the problem - https://shardingsphere.apache.org/document/current/en/faq/#single-table-table-or-view-s-does-not-exist-how-to-solve-the-exception. For question 1 and 3, you can try the master branch, we are trying to be compatible with more system table query statements.

zzyReal666 commented 5 months ago

For question 2, you can read faq to solve the problem - https://shardingsphere.apache.org/document/current/en/faq/#single-table-table-or-view-s-does-not-exist-how-to-solve-the-exception. For question 1 and 3, you can try the master branch, we are trying to be compatible with more system table query statements.

Thanks for your replay.

Question 2 and 3 has been resloved,as for question 1,error information changed to java.sql.SQLSyntaxErrorException: Table 'mysql.proc' doesn't exist . But it does not affect proxy execution. image

zzyReal666 commented 5 months ago

@godojoe I use latest code ,branch master,resolved error java.sql.SQLException: 'information_schema.INNODB_TABLESTATS' is not VIEW, java.sql.SQLException: 'information_schema.INNODB_TRX' is not VIEW,and Nullpointer exception,maybe you can have a try.

github-actions[bot] commented 4 months ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

github-actions[bot] commented 2 months ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.