[jira] [Commented] (CALCITE-3606) batch insert failed
[ https://issues.apache.org/jira/browse/CALCITE-3606?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17003595#comment-17003595 ] Jin Xing commented on CALCITE-3606: --- Hi Ran ~ I proposed a PR to fix the case you provided ~ Please check ~ Jin > batch insert failed > --- > > Key: CALCITE-3606 > URL: https://issues.apache.org/jira/browse/CALCITE-3606 > Project: Calcite > Issue Type: Wish > Components: core >Affects Versions: 1.21.0 >Reporter: Ran Cao >Priority: Major > Labels: pull-request-available > Time Spent: 10m > Remaining Estimate: 0h > > when I try to execute sql like (insert into example_table (column1,column2) > values (value1,value2),(value1,value2)), it will failed with error message > like this: column "EXPR$0" of relation "example_table" does not exist. I find > the reason is that when converting SqlNode(insert sql) to > RelNode(TableModify), one of the steps is to change the column that stored in > RelDataType from the fake column name (like "EXPR$0") to the real column name > (like "id"). But when the values part in sql is more than one , the step > above-mentioned will skip because the RelNode is instance of LogicalUnion > instead of Project, the code refered to org.apache.calcite.tools.RelBuilder > line 1461: > if (input instanceof Project && fieldNames != null) { > // change the column name > } > -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (CALCITE-3606) batch insert failed
[ https://issues.apache.org/jira/browse/CALCITE-3606?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16999883#comment-16999883 ] Ran Cao commented on CALCITE-3606: -- {code:java} final RelToSqlConverter converter = new RelToSqlConverter(SqlDialect.DatabaseProduct.CALCITE.getDialect()); @Test public void test() throws Exception { String singleColumnSql = "INSERT INTO DEPT VALUES (?,?)"; String multiColumnsSql = "INSERT INTO DEPT VALUES (?,?),(?,?)"; assertEquals(transform(singleColumnSql), "INSERT INTO \"CATALOG\".\"SALES\".\"DEPT\" (\"DEPTNO\", \"NAME\")\r\n" + "(SELECT ? AS \"DEPTNO\", ? AS \"NAME\"\r\n" + "FROM (VALUES (0)) AS \"t\" (\"ZERO\"))"); assertEquals(transform(multiColumnsSql), "INSERT INTO \"CATALOG\".\"SALES\".\"DEPT\" (\"EXPR$0\", \"EXPR$1\")\r\n" + "SELECT ?, ?\r\n" + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")\r\n" + "UNION ALL\r\n" + "SELECT ?, ?\r\n" + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")"); } private String transform(String sql) { RelRoot relRoot = tester.convertSqlToRel(sql); final SqlNode sqlNode = converter.visitChild(0, relRoot.rel).asStatement(); return sqlNode.toSqlString(SqlDialect.DatabaseProduct.CALCITE.getDialect()).getSql(); }{code} after transform, the second sql's column name was wrong. > batch insert failed > --- > > Key: CALCITE-3606 > URL: https://issues.apache.org/jira/browse/CALCITE-3606 > Project: Calcite > Issue Type: Wish > Components: core >Affects Versions: 1.21.0 >Reporter: Ran Cao >Priority: Major > > when I try to execute sql like (insert into example_table (column1,column2) > values (value1,value2),(value1,value2)), it will failed with error message > like this: column "EXPR$0" of relation "example_table" does not exist. I find > the reason is that when converting SqlNode(insert sql) to > RelNode(TableModify), one of the steps is to change the column that stored in > RelDataType from the fake column name (like "EXPR$0") to the real column name > (like "id"). But when the values part in sql is more than one , the step > above-mentioned will skip because the RelNode is instance of LogicalUnion > instead of Project, the code refered to org.apache.calcite.tools.RelBuilder > line 1461: > if (input instanceof Project && fieldNames != null) { > // change the column name > } > -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (CALCITE-3606) batch insert failed
[ https://issues.apache.org/jira/browse/CALCITE-3606?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16999003#comment-16999003 ] Danny Chen commented on CALCITE-3606: - Thanks [~caoran] for reporting this, a re-producable test case would help a lot, you can add one in JdbcTest or RelOptRulesTest. > batch insert failed > --- > > Key: CALCITE-3606 > URL: https://issues.apache.org/jira/browse/CALCITE-3606 > Project: Calcite > Issue Type: Wish > Components: core >Affects Versions: 1.21.0 >Reporter: Ran Cao >Priority: Major > > when I try to execute sql like (insert into example_table (column1,column2) > values (value1,value2),(value1,value2)), it will failed with error message > like this: column "EXPR$0" of relation "example_table" does not exist. I find > the reason is that when converting SqlNode(insert sql) to > RelNode(TableModify), one of the steps is to change the column that stored in > RelDataType from the fake column name (like "EXPR$0") to the real column name > (like "id"). But when the values part in sql is more than one , the step > above-mentioned will skip because the RelNode is instance of LogicalUnion > instead of Project, the code refered to org.apache.calcite.tools.RelBuilder > line 1461: > if (input instanceof Project && fieldNames != null) { > // change the column name > } > -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (CALCITE-3606) batch insert failed
[ https://issues.apache.org/jira/browse/CALCITE-3606?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16998815#comment-16998815 ] Jin Xing commented on CALCITE-3606: --- Hi, Ran Cao ~ Yes, seems current RelBuilder#projectNamed failed to rename the fields. If we run below tests {code:java} @Test public void testDEV() { final RelBuilder builder = RelBuilder.create(config().build()); RelNode rel = builder .values(new String[] {"x"}, 0) .values(new String[] {"y"}, 1) .union(true) .projectNamed( ImmutableList.of(builder.field(0)), ImmutableList.of("col0"), false) .build(); System.out.println(rel.getRowType()); System.out.println(RelOptUtil.toString(rel)); }{code} We get {code:java} RecordType(INTEGER x) LogicalUnion(all=[true]) LogicalValues(tuples=[[{ 0 }]]) LogicalValues(tuples=[[{ 1 }]]) {code} As we can see, the row type is not as expected. For the exception you mentioned – – _*column "EXPR$0" of relation "example_table" does not exist,*_ would you please elaborate by stacktrace or unit test? Best, Jin > batch insert failed > --- > > Key: CALCITE-3606 > URL: https://issues.apache.org/jira/browse/CALCITE-3606 > Project: Calcite > Issue Type: Wish > Components: core >Affects Versions: 1.21.0 >Reporter: Ran Cao >Priority: Major > > when I try to execute sql like (insert into example_table (column1,column2) > values (value1,value2),(value1,value2)), it will failed with error message > like this: column "EXPR$0" of relation "example_table" does not exist. I find > the reason is that when converting SqlNode(insert sql) to > RelNode(TableModify), one of the steps is to change the column that stored in > RelDataType from the fake column name (like "EXPR$0") to the real column name > (like "id"). But when the values part in sql is more than one , the step > above-mentioned will skip because the RelNode is instance of LogicalUnion > instead of Project, the code refered to org.apache.calcite.tools.RelBuilder > line 1461: > if (input instanceof Project && fieldNames != null) { > // change the column name > } > -- This message was sent by Atlassian Jira (v8.3.4#803005)