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

Trino 370 fails when casting to DECIMAL(38, 38) #10946

Closed
hashhar opened this issue Feb 4, 2022 · 1 comment
Closed

Trino 370 fails when casting to DECIMAL(38, 38) #10946

hashhar opened this issue Feb 4, 2022 · 1 comment
Assignees

Comments

@hashhar
Copy link
Member

hashhar commented Feb 4, 2022

Apply following patch to add a test case to showcase failure:

diff --git a/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlTypeMapping.java b/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlTypeMapping.java
index 18edfc1e40..73ad0e787b 100644
--- a/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlTypeMapping.java
+++ b/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlTypeMapping.java
@@ -256,6 +256,8 @@ public class TestPostgreSqlTypeMapping
                 .addRoundTrip("decimal(30, 5)", "CAST('-3141592653589793238462643.38327' AS decimal(30, 5))", createDecimalType(30, 5), "CAST('-3141592653589793238462643.38327' AS decimal(30, 5))")
                 .addRoundTrip("decimal(38, 0)", "CAST('27182818284590452353602874713526624977' AS decimal(38, 0))", createDecimalType(38, 0), "CAST('27182818284590452353602874713526624977' AS decimal(38, 0))")
                 .addRoundTrip("decimal(38, 0)", "CAST('-27182818284590452353602874713526624977' AS decimal(38, 0))", createDecimalType(38, 0), "CAST('-27182818284590452353602874713526624977' AS decimal(38, 0))")
+                .addRoundTrip("decimal(38, 38)", "CAST('0.27182818284590452353602874713526624977' AS decimal(38, 38))", createDecimalType(38, 38), "CAST('0.27182818284590452353602874713526624977' AS decimal(38, 38))")
+                .addRoundTrip("decimal(38, 38)", "CAST('-0.27182818284590452353602874713526624977' AS decimal(38, 38))", createDecimalType(38, 38), "CAST('-0.27182818284590452353602874713526624977' AS decimal(38, 38))")
                 .execute(getQueryRunner(), postgresCreateAndInsert("test_decimal"))
                 .execute(getQueryRunner(), trinoCreateAsSelect("test_decimal"));
 

Run the test and it fails with:

java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: Index 38 out of bounds for length 38

	at io.trino.testing.AbstractTestingTrinoClient.execute(AbstractTestingTrinoClient.java:123)
	at io.trino.testing.DistributedQueryRunner.execute(DistributedQueryRunner.java:505)
	at io.trino.testing.datatype.SqlDataTypeTest.verifySelect(SqlDataTypeTest.java:91)
	at io.trino.testing.datatype.SqlDataTypeTest.execute(SqlDataTypeTest.java:79)
	at io.trino.testing.datatype.SqlDataTypeTest.execute(SqlDataTypeTest.java:72)
	at io.trino.plugin.postgresql.TestPostgreSqlTypeMapping.testDecimal(TestPostgreSqlTypeMapping.java:261)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
	at org.testng.TestRunner.privateRun(TestRunner.java:756)
	at org.testng.TestRunner.run(TestRunner.java:610)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
	at org.testng.SuiteRunner.run(SuiteRunner.java:289)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
	at org.testng.TestNG.runSuites(TestNG.java:1133)
	at org.testng.TestNG.run(TestNG.java:1104)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
	Suppressed: java.lang.Exception: SQL: VALUES ROW(CAST('193' AS decimal(3, 0)),CAST('19' AS decimal(3, 0)),CAST('-193' AS decimal(3, 0)),CAST('10.0' AS decimal(3, 1)),CAST('10.1' AS decimal(3, 1)),CAST('-10.1' AS decimal(3, 1)),CAST('2' AS decimal(4, 2)),CAST('2.3' AS decimal(4, 2)),CAST('2' AS decimal(24, 2)),CAST('2.3' AS decimal(24, 2)),CAST('123456789.3' AS decimal(24, 2)),CAST('12345678901234567890.31' AS decimal(24, 4)),CAST('3141592653589793238462643.38327' AS decimal(30, 5)),CAST('-3141592653589793238462643.38327' AS decimal(30, 5)),CAST('27182818284590452353602874713526624977' AS decimal(38, 0)),CAST('-27182818284590452353602874713526624977' AS decimal(38, 0)),CAST('0.27182818284590452353602874713526624977' AS decimal(38, 38)),CAST('-0.27182818284590452353602874713526624977' AS decimal(38, 38)))
		at io.trino.testing.DistributedQueryRunner.execute(DistributedQueryRunner.java:508)
		... 28 more
Caused by: java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: Index 38 out of bounds for length 38
	at io.trino.metadata.FunctionRegistry.getScalarFunctionInvoker(FunctionRegistry.java:886)
	at io.trino.metadata.MetadataManager.getScalarFunctionInvoker(MetadataManager.java:2302)
	at io.trino.sql.InterpretedFunctionInvoker.invoke(InterpretedFunctionInvoker.java:63)
	at io.trino.sql.planner.ExpressionInterpreter$Visitor.visitCast(ExpressionInterpreter.java:1252)
	at io.trino.sql.tree.Cast.accept(Cast.java:91)
	at io.trino.sql.tree.AstVisitor.process(AstVisitor.java:27)
	at io.trino.sql.planner.ExpressionInterpreter$Visitor.processWithExceptionHandling(ExpressionInterpreter.java:302)
	at io.trino.sql.planner.ExpressionInterpreter.optimize(ExpressionInterpreter.java:282)
	at io.trino.sql.planner.iterative.rule.SimplifyExpressions.rewrite(SimplifyExpressions.java:54)
	at io.trino.sql.planner.iterative.rule.SimplifyExpressions.lambda$createRewrite$0(SimplifyExpressions.java:79)
	at io.trino.sql.planner.iterative.rule.ExpressionRewriteRuleSet$ValuesExpressionRewrite.lambda$apply$0(ExpressionRewriteRuleSet.java:343)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
	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 io.trino.sql.planner.iterative.rule.ExpressionRewriteRuleSet$ValuesExpressionRewrite.apply(ExpressionRewriteRuleSet.java:344)
	at io.trino.sql.planner.iterative.rule.ExpressionRewriteRuleSet$ValuesExpressionRewrite.apply(ExpressionRewriteRuleSet.java:313)
	at io.trino.sql.planner.iterative.IterativeOptimizer.transform(IterativeOptimizer.java:202)
	at io.trino.sql.planner.iterative.IterativeOptimizer.exploreNode(IterativeOptimizer.java:169)
	at io.trino.sql.planner.iterative.IterativeOptimizer.exploreGroup(IterativeOptimizer.java:132)
	at io.trino.sql.planner.iterative.IterativeOptimizer.exploreChildren(IterativeOptimizer.java:235)
	at io.trino.sql.planner.iterative.IterativeOptimizer.exploreGroup(IterativeOptimizer.java:134)
	at io.trino.sql.planner.iterative.IterativeOptimizer.optimize(IterativeOptimizer.java:117)
	at io.trino.sql.planner.LogicalPlanner.plan(LogicalPlanner.java:230)
	at io.trino.sql.planner.LogicalPlanner.plan(LogicalPlanner.java:215)
	at io.trino.sql.planner.LogicalPlanner.plan(LogicalPlanner.java:210)
	at io.trino.execution.SqlQueryExecution.doPlanQuery(SqlQueryExecution.java:474)
	at io.trino.execution.SqlQueryExecution.planQuery(SqlQueryExecution.java:455)
	at io.trino.execution.SqlQueryExecution.start(SqlQueryExecution.java:396)
	at io.trino.execution.SqlQueryManager.createQuery(SqlQueryManager.java:243)
	at io.trino.dispatcher.LocalDispatchQuery.lambda$startExecution$7(LocalDispatchQuery.java:143)
	at io.trino.$gen.Trino_testversion____20220204_105233_3.run(Unknown Source)
	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)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 38 out of bounds for length 38
	at io.trino.spi.type.Int128Math.powerOfTen(Int128Math.java:103)
	at io.trino.type.DecimalCasts.lambda$castFunctionToDecimalFromBuilder$3(DecimalCasts.java:150)
	at io.trino.metadata.PolymorphicScalarFunction.lambda$computeExtraParameters$0(PolymorphicScalarFunction.java:145)
	at java.base/java.util.Optional.map(Optional.java:260)
	at io.trino.metadata.PolymorphicScalarFunction.computeExtraParameters(PolymorphicScalarFunction.java:145)
	at io.trino.metadata.PolymorphicScalarFunction.getScalarFunctionImplementationChoice(PolymorphicScalarFunction.java:87)
	at io.trino.metadata.PolymorphicScalarFunction.specialize(PolymorphicScalarFunction.java:58)
	at io.trino.metadata.SqlScalarFunction.specialize(SqlScalarFunction.java:36)
	at io.trino.metadata.FunctionRegistry.specializeScalarFunction(FunctionRegistry.java:894)
	at io.trino.metadata.FunctionRegistry.lambda$getScalarFunctionInvoker$2(FunctionRegistry.java:882)
	at com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4868)
	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3533)
	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2282)
	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2159)
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2049)
	at com.google.common.cache.LocalCache.get(LocalCache.java:3966)
	at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4863)
	at com.google.common.cache.ForwardingCache.get(ForwardingCache.java:55)
	at io.trino.metadata.FunctionRegistry.getScalarFunctionInvoker(FunctionRegistry.java:882)
	... 37 more

Introduced by e8bdbee (#10404)

@hashhar hashhar changed the title Trino 370 DECIMAL(p, 38) is broken Trino 370 fails when casting to DECIMAL(38, 38) Feb 4, 2022
@dain dain closed this as completed Feb 5, 2022
@dain
Copy link
Member

dain commented Feb 5, 2022

This was fixed by #10951. The PR was merged manually.

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

Successfully merging a pull request may close this issue.

3 participants