You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "slim bouguerra (JIRA)" <ji...@apache.org> on 2018/01/05 18:01:00 UTC

[jira] [Created] (CALCITE-2121) CAST timestamp with time zone to SQL VARCHAR

slim bouguerra created CALCITE-2121:
---------------------------------------

             Summary: CAST timestamp with time zone to SQL VARCHAR
                 Key: CALCITE-2121
                 URL: https://issues.apache.org/jira/browse/CALCITE-2121
             Project: Calcite
          Issue Type: Bug
          Components: core
            Reporter: slim bouguerra
            Assignee: Julian Hyde


Running the following test  at org.apache.calcite.test.DruidAdapterIT
{code}
@Test
  public void testCastTimestampWithTimeZone() {
    final String sql = "SELECT CAST(\"timestamp\" AS VARCHAR) FROM \"foodmart\"";
    sql(sql, FOODMART).runs();
  }
{code}
leads to 
{code} 
2018-01-05 09:56:57,358 [main] ERROR - org.apache.calcite.sql.validate.SqlValidatorException: Cast function cannot convert value of type TIMESTAMP_WITH_LOCAL_TIME_ZONE(0) to type VARCHAR
2018-01-05 09:56:57,360 [main] ERROR - org.apache.calcite.runtime.CalciteContextException: From line 1, column 8 to line 1, column 35: Cast function cannot convert value of type TIMESTAMP_WITH_LOCAL_TIME_ZONE(0) to type VARCHAR

java.lang.RuntimeException: exception while executing [SELECT CAST("timestamp" AS VARCHAR) FROM "foodmart"]

	at org.apache.calcite.test.CalciteAssert$AssertQuery.runs(CalciteAssert.java:1411)
	at org.apache.calcite.test.DruidAdapterIT.testCastTimestampWithTimeZone(DruidAdapterIT.java:3503)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.RuntimeException: With materializationsEnabled=false, limit=0
	at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:600)
	at org.apache.calcite.test.CalciteAssert$AssertQuery.runs(CalciteAssert.java:1407)
	... 23 more
Caused by: java.sql.SQLException: Error while executing SQL "SELECT CAST("timestamp" AS VARCHAR) FROM "foodmart"": From line 1, column 8 to line 1, column 35: Cast function cannot convert value of type TIMESTAMP_WITH_LOCAL_TIME_ZONE(0) to type VARCHAR
	at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
	at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
	at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
	at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
	at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:568)
	... 24 more
Caused by: org.apache.calcite.runtime.CalciteContextException: From line 1, column 8 to line 1, column 35: Cast function cannot convert value of type TIMESTAMP_WITH_LOCAL_TIME_ZONE(0) to type VARCHAR
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
	at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:803)
	at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:788)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:4703)
	at org.apache.calcite.sql.SqlCallBinding.newError(SqlCallBinding.java:275)
	at org.apache.calcite.sql.fun.SqlCastFunction.checkOperandTypes(SqlCastFunction.java:142)
	at org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:432)
	at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:287)
	at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
	at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5429)
	at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5416)
	at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:460)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:3966)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3229)
	at org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
	at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:947)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:928)
	at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:226)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
	at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
	at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230)
	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
	at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
	at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
	at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
	at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
	at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
	... 26 more
Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Cast function cannot convert value of type TIMESTAMP_WITH_LOCAL_TIME_ZONE(0) to type VARCHAR
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
	at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572)
	... 59 more

{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)