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

Parse engine rejects CURRENT_USER in 4.0.0 #3990

Closed
encodeering opened this issue Jan 15, 2020 · 4 comments · Fixed by #3994
Closed

Parse engine rejects CURRENT_USER in 4.0.0 #3990

encodeering opened this issue Jan 15, 2020 · 4 comments · Fixed by #3994

Comments

@encodeering
Copy link

Bug Report

Which version of ShardingSphere did you use?

4.0.0

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

Sharding-JDBC

Expected behavior

Update from 3.1.0 to 4.0.0 would not change the parser rules.

Actual behavior

Integration tests fail because flyway can't perform a migration when executing select CURRENT_USER

Reason analyze (If you can)

org.postgresql:postgresql:42.2.6
org.flywaydb:flyway-core:5.2.4
org.testcontainers:postgresql:1.12.0

sql = "SELECT CURRENT_USER"
parseEngine = {SQLParseEngine@4966} 
 databaseTypeName = "PostgreSQL"

line 1:7 mismatched input 'CURRENT_USER' expecting {'U', 'u', '!', '~', '+', '-', '*', '(', '{', '?', INSERT, UPDATE, DELETE, ALTER, DROP, TRUNCATE, SCHEMA, REVOKE, ADD, SET, INDEX, KEY, FUNCTION, TRIGGER, PROCEDURE, DISTINCT, CASE, CAST, IF, NOT, NULL, TRUE, FALSE, EXISTS, ALL, BEGIN, COMMIT, ROLLBACK, SAVEPOINT, BOOLEAN, CHAR, INTERVAL, TIME, TIMESTAMP, LOCALTIME, LOCALTIMESTAMP, YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MAX, MIN, SUM, COUNT, AVG, CURRENT, ENABLE, DISABLE, INSTANCE, PRESERVE, DEFINER, SQL, CASCADED, LOCAL, CLOSE, OPEN, NEXT, NAME, NAMES, INTEGER, REAL, DECIMAL, TYPE, ADMIN, BINARY, ESCAPE, EXCLUDE, PARTITION, ROW, UNKNOWN, ALWAYS, CASCADE, GENERATED, ISOLATION, LEVEL, OPTION, PRIVILEGES, READ, ROLE, ROWS, START, TRANSACTION, ACTION, CACHE, CHARACTERISTICS, CLUSTER, COMMENTS, CONSTRAINTS, CURRENT_TIMESTAMP, CYCLE, DATA, DATABASE, DEFAULTS, DEFERRED, DEPENDS, DOMAIN, EXCLUDING, EXECUTE, EXTENDED, EXTENSION, EXTERNAL, EXTRACT, FILTER, FIRST, FOLLOWING, FORCE, GLOBAL, IDENTITY, IMMEDIATE, INCLUDING, INCREMENT, INDEXES, INHERIT, INHERITS, INCLUDE, LANGUAGE, LARGE, LAST, LOGGED, MAIN, MATCH, MAXVALUE, MINVALUE, NOTHING, NULLS, OBJECT, OIDS, OVER, OWNED, OWNER, PARTIAL, PLAIN, PRECEDING, RANGE, RENAME, REPLICA, RESET, RESTART, RESTRICT, ROUTINE, RULE, SECURITY, SEQUENCE, SESSION, SHOW, SIMPLE, STATISTICS, STORAGE, TABLESPACE, TEMP, TEMPORARY, UNBOUNDED, UNLOGGED, USAGE, VALID, VALIDATE, WITHIN, WITHOUT, ZONE, OF, GROUPS, RECURSIVE, IDENTIFIER_, STRING_, NUMBER_, HEX_DIGIT_, BIT_NUM_}

java.lang.IllegalStateException
	at com.google.common.base.Preconditions.checkState(Preconditions.java:429)
	at org.apache.shardingsphere.sql.parser.core.extractor.util.ExtractorUtils.getFirstChildNode(ExtractorUtils.java:48)
	at org.apache.shardingsphere.sql.parser.core.extractor.impl.dml.select.SelectItemsExtractor.extract(SelectItemsExtractor.java:54)
	at org.apache.shardingsphere.sql.parser.core.extractor.SQLSegmentsExtractorEngine.extract(SQLSegmentsExtractorEngine.java:47)
	at org.apache.shardingsphere.sql.parser.core.SQLParseKernel.parse(SQLParseKernel.java:59)
	at org.apache.shardingsphere.sql.parser.SQLParseEngine.parse0(SQLParseEngine.java:70)
	at org.apache.shardingsphere.sql.parser.SQLParseEngine.parse(SQLParseEngine.java:52)
	at org.apache.shardingsphere.core.route.router.masterslave.MasterSlaveRouter.route(MasterSlaveRouter.java:56)
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.MasterSlavePreparedStatement.<init>(MasterSlavePreparedStatement.java:68)
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.MasterSlavePreparedStatement.<init>(MasterSlavePreparedStatement.java:53)
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.MasterSlaveConnection.prepareStatement(MasterSlaveConnection.java:76)
	at org.flywaydb.core.internal.jdbc.JdbcTemplate.prepareStatement(JdbcTemplate.java:333)
	at org.flywaydb.core.internal.jdbc.JdbcTemplate.queryForString(JdbcTemplate.java:190)
	at org.flywaydb.core.internal.database.postgresql.PostgreSQLConnection.<init>(PostgreSQLConnection.java:48)
	at org.flywaydb.core.internal.database.postgresql.PostgreSQLDatabase.getConnection(PostgreSQLDatabase.java:56)
	at org.flywaydb.core.internal.database.postgresql.PostgreSQLDatabase.getConnection(PostgreSQLDatabase.java:31)
	at org.flywaydb.core.internal.database.base.Database.getMainConnection(Database.java:366)
	at org.flywaydb.core.Flyway.prepareSchemas(Flyway.java:1773)
	at org.flywaydb.core.Flyway.execute(Flyway.java:1678)
	at org.flywaydb.core.Flyway.migrate(Flyway.java:1356)

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

Should be reproducible if the mentioned statement is executed with the PostgreSQL SQLParseEngine

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

@SteNicholas
Copy link
Member

SteNicholas commented Jan 16, 2020

@encodeering 4.0.0 PostgreSQLParser doesn't support SELECT CURRENT_USER, I would like to add the keyword to simpleExpr.

@encodeering
Copy link
Author

Hi @SteNicholas @terrymanu, thanks for the fast reply.

Could you please point me to a maven repository where I could test the current snapshot?
Would it be possible to have this change also part of a 4.0.x release if the schedule for 5.x is not yet known?

@SteNicholas
Copy link
Member

SteNicholas commented Jan 20, 2020

@encodeering Hi encodeering, you should clone the shardingsphere to local, checkout the dev branch, and execute mvn clean install -DskipTests -Dfast to compile. Then you could use the compiled version for you application. 5.X version doesn't release. If you don't have any question, please close this issue. Thanks.

@SteNicholas SteNicholas reopened this Jan 20, 2020
@encodeering
Copy link
Author

Okay, will do that, thanks for the command line 👍

@terrymanu terrymanu modified the milestones: 5.0.0, 4.1.0 Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants