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

CalciteSqlParser fails to parse table name from queries with window functions #15204

Open
AlexanderKM opened this issue Mar 5, 2025 · 0 comments
Labels

Comments

@AlexanderKM
Copy link
Contributor

We use the RequestUtils#getTableNames a bit on our end to track and report which tables our queries are hitting, and this method seems to be failing for queries that contain window functions. Under the hood, the CalciteSqlParser is failing in the method compileSqlNodeToPinotQuery

Example query:

SET useMultiStageEngine=true; 

SELECT foo, occurredAt, LAG(occurredAt) OVER (PARTITION BY foo ORDER BY occurredAt) lag

Which gives this exception:

java.lang.ClassCastException: class org.apache.calcite.sql.SqlWindow cannot be cast to class org.apache.calcite.sql.SqlBasicCall (org.apache.calcite.sql.SqlWindow and org.apache.calcite.sql.SqlBasicCall are in unnamed module of loader 'app')

	at org.apache.pinot.sql.parsers.CalciteSqlParser.toExpression(CalciteSqlParser.java:740)
	at org.apache.pinot.sql.parsers.CalciteSqlParser.compileFunctionExpression(CalciteSqlParser.java:802)
	at org.apache.pinot.sql.parsers.CalciteSqlParser.toExpression(CalciteSqlParser.java:740)
	at org.apache.pinot.sql.parsers.CalciteSqlParser.toExpression(CalciteSqlParser.java:690)
	at org.apache.pinot.sql.parsers.CalciteSqlParser.convertSelectList(CalciteSqlParser.java:608)
	at org.apache.pinot.sql.parsers.CalciteSqlParser.compileWithoutRewrite(CalciteSqlParser.java:461)
	at org.apache.pinot.sql.parsers.CalciteSqlParser.compileSqlNodeToPinotQuery(CalciteSqlParser.java:427)
	at org.apache.pinot.common.utils.request.RequestUtilsTest.testResolveTableNames(RequestUtilsTest.java:82)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:141)
	at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:687)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:230)
	at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:63)
	at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:995)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:203)
	at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:154)
	at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:134)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at org.testng.TestRunner.privateRun(TestRunner.java:741)
	at org.testng.TestRunner.run(TestRunner.java:616)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:421)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:413)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:373)
	at org.testng.SuiteRunner.run(SuiteRunner.java:312)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1274)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1208)
	at org.testng.TestNG.runSuites(TestNG.java:1112)
	at org.testng.TestNG.run(TestNG.java:1079)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:65)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105)

I have added a test here to show the example: 25e3dc4

This is likely a similar issue to #11313
And others have pointed out this issue on slack: https://apache-pinot.slack.com/archives/C011C9JHN7R/p1707886703534859

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants