calcite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Atkinson <chris.atkins...@ocado.com>
Subject Fwd: Cast function for Oracle
Date Fri, 11 Mar 2016 10:15:27 GMT
I did post this to the apache drill list but after digging in the code I
discovered that the SQL generation is build by Calcite in

drill/contrib/storage-jdbc/src/main/java/org/apache/drill/exec/store/jdbc/JdbcPrel.java:
...
org.apache.calcite.adapter.jdbc.JdbcImplementor
...
public JdbcPrel(...){...
final SqlDialect dialect = convention.getPlugin().getDialect();
    final JdbcImplementor jdbcImplementor = new JdbcImplementor(
        dialect,
        (JavaTypeFactory) getCluster().getTypeFactory());
    final JdbcImplementor.Result result =
        jdbcImplementor.visitChild(0, input.accept(new SubsetRemover()));
    sql = result.asQuery().toSqlString(dialect).getSql();
...}

The following is still applicable... the cast isn't valid for Oracle SQL:

I'm trying to join two VARCHAR2 columns of differing length.  The generate
SQL casts the shorter to match the longer.

create table myschema.a_table(
  description varchar2(10)
);

create table myschema.b_table(
  description20 varchar2(20)
);

When the join is attempted

0: jdbc:drill:zk=local> select *
. . . . . . . . . . . >   from utd_utpdba.UTPDBA.A_TABLE
. . . . . . . . . . . >  inner join utd_utpdba.UTPDBA.B_TABLE
. . . . . . . . . . . >     on A_TABLE.DESCRIPTION = B_TABLE.DESCRIPTION20;

The following CAST pattern is not acceptable to Oracle (11.2)

Error: DATA_READ ERROR: The JDBC storage plugin failed while trying setup
the SQL query.

sql SELECT *
FROM (SELECT "DESCRIPTION", CAST("DESCRIPTION" AS VARCHAR(20) CHARACTER SET
"ISO-8859-1") "$f2"
FROM "UTPDBA"."A_TABLE") "t"
INNER JOIN "UTPDBA"."B_TABLE" ON "t"."$f2" = "B_TABLE"."DESCRIPTION20"
plugin utd_utpdba
Fragment 0:0

[Error Id: 2f9a1975-fa57-4b07-8642-4dca3d03ae39 on x.x.x.x:31010]

  (java.sql.SQLSyntaxErrorException) ORA-00907: missing right parenthesis

    oracle.jdbc.driver.T4CTTIoer.processError():450
....
    java.lang.Thread.run():745 (state=,code=0)


Specifically, CHARACTER SET "ISO-8859-1" is not allowed in the cast
statement:

*CAST*({ expr | *MULTISET* (subquery) } *AS* type_name)

https://docs.oracle.com/cd/B28359_01/server.111/b28286/functions016.htm


Cheers!

-- 


Notice:  This email is confidential and may contain copyright material of 
members of the Ocado Group. Opinions and views expressed in this message 
may not necessarily reflect the opinions and views of the members of the 
Ocado Group. 

 

If you are not the intended recipient, please notify us immediately and 
delete all copies of this message. Please note that it is your 
responsibility to scan this message for viruses. 

 

Fetch and Sizzle are trading names of Speciality Stores Limited, a member 
of the Ocado Group.

 

References to the “Ocado Group” are to Ocado Group plc (registered in 
England and Wales with number 7098618) and its subsidiary undertakings (as 
that expression is defined in the Companies Act 2006) from time to time.  
The registered office of Ocado Group plc is Titan Court, 3 Bishops Square, 
Hatfield Business Park, Hatfield, Herts. AL10 9NE.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message