apache / shardingsphere

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

ClassCastException occur when select schema infomation in aggregation segment #21713

Open MaricoHan opened 1 year ago

MaricoHan commented 1 year ago

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

docker image-5.2.1

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

ShardingSphere-Proxy

Expected behavior

Parse SQL correctly.

SELECT COUNT(*) FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'awsdms_control';

Actual behavior

[ERROR] 2022-10-24 05:40:47.052 [Connection-2-ThreadExecutor] o.a.s.p.f.c.CommandExecutorTask - Exception occur: 
java.lang.ClassCastException: class org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment cannot be cast to class org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment (org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment and org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment are in unnamed module of loader 'app')
    at org.apache.shardingsphere.proxy.backend.handler.admin.mysql.executor.information.SelectInformationSchemataExecutor.lambda$getTheDefaultRowData$10(SelectInformationSchemataExecutor.java:128)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.LinkedList$LLSpliterator.forEachRemaining(LinkedList.java:1242)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at org.apache.shardingsphere.proxy.backend.handler.admin.mysql.executor.information.SelectInformationSchemataExecutor.getTheDefaultRowData(SelectInformationSchemataExecutor.java:128)
    at org.apache.shardingsphere.proxy.backend.handler.admin.mysql.executor.information.SelectInformationSchemataExecutor.fillSchemasWithoutDataSource(SelectInformationSchemataExecutor.java:113)
    at org.apache.shardingsphere.proxy.backend.handler.admin.mysql.executor.information.SelectInformationSchemataExecutor.getDatabaseNames(SelectInformationSchemataExecutor.java:90)
    at org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetadataExecutor.execute(AbstractDatabaseMetadataExecutor.java:73)
    at org.apache.shardingsphere.proxy.backend.handler.admin.DatabaseAdminQueryBackendHandler.execute(DatabaseAdminQueryBackendHandler.java:56)
    at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:94)
    at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:110)
    at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:77)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)

Reason analyze (If you can)

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

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

strongduanmu commented 1 year ago

Hi @MaricoHan, thank you for your feedback. ShardingSphere does not support system table query now. But I think we can optimize the sql parse first.