You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Nandakishore Mm <na...@flipkart.com.INVALID> on 2019/06/18 09:22:28 UTC

'INSERT' statements doesn't work for nested schema tables

Assume the following table structure -
Table - Orders
Fields -

   1. id INTEGER
   2. product VARCHAR(20)
   3. units INTEGER
   4. name (has sub schema)
      1. firstname VARCHAR(50)
      2. lastname VARCHAR(50)

The following query works -
INSERT INTO Orders SELECT * FROM Orders

The following queries doesn't work (along with the error) -

   1. INSERT INTO Orders SELECT 1, "bulb", 3, ROW("fname", "lname") -
      1. Caused by: org.apache.calcite.sql.validate.SqlValidatorException:
      Cannot assign to target field 'name' of type RecordType(VARCHAR(50)
      firstname, VARCHAR(50) lastname) from source field 'EXPR$3' of type
      RecordType(CHAR(4) EXPR$0, CHAR(4) EXPR$1)
      at
      java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native
      Method)
      at
      java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at
      java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      2. - INSERT INTO Orders SELECT 1, "bulb", 3, ROW(CAST("fname" AS
   VARCHAR(50)), CAST("lname" AS VARCHAR(50))) as name -
      1. Caused by: org.apache.calcite.sql.validate.SqlValidatorException:
      Cannot assign to target field 'name' of type RecordType(VARCHAR(50)
      firstname, VARCHAR(50) lastname) from source field 'name' of type
      RecordType(VARCHAR(50) EXPR$0, VARCHAR(50) EXPR$1)
      at
      java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native
      Method)
      at
      java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at
      java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

Since the first query work there is enough reason to believe that inserting
into nested schema is possible, but we are unable to do with a custom
select statement.
Could someone please help resolve the issue?

Thanks and regards,
-- 
Nandakishore MM
Mobile : +91 9043412922