[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2020-06-22 Thread Danny Chen (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17141887#comment-17141887
 ] 

Danny Chen commented on CALCITE-2336:
-

Yes, thanks for the reminder [~Leonard Xu], i will close the issue, [~xu fei], 
try the master to see if the problem exists, feel free to re-open it.

> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Priority: Major
> Attachments: 1.patch
>
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I get what I need.
> {code:java}
> && targetRowType.getFieldCount() - 1 >= i  
> ? targetRowType.getFieldList().get(i).getType(){code}
> So is this a Bug ? Do we need fix it ? 
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2020-06-22 Thread Leonard Xu (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17141817#comment-17141817
 ] 

Leonard Xu commented on CALCITE-2336:
-

This issue has been fixed int CALCITE-3148

> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Priority: Major
> Attachments: 1.patch
>
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I get what I need.
> {code:java}
> && targetRowType.getFieldCount() - 1 >= i  
> ? targetRowType.getFieldList().get(i).getType(){code}
> So is this a Bug ? Do we need fix it ? 
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-31 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16497488#comment-16497488
 ] 

yuqi commented on CALCITE-2336:
---

[~xu fei] You can make a MR about this problem or i do it later

> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
> Attachments: 1.patch
>
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I get what I need.
> {code:java}
> && targetRowType.getFieldCount() - 1 >= i  
> ? targetRowType.getFieldList().get(i).getType(){code}
> So is this a Bug ? Do we need fix it ? 
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-31 Thread Fei Xu (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16497486#comment-16497486
 ] 

Fei Xu commented on CALCITE-2336:
-

Thanks, It's more clear

> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
> Attachments: 1.patch
>
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I get what I need.
> {code:java}
> && targetRowType.getFieldCount() - 1 >= i  
> ? targetRowType.getFieldList().get(i).getType(){code}
> So is this a Bug ? Do we need fix it ? 
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-31 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496548#comment-16496548
 ] 

yuqi commented on CALCITE-2336:
---

[~xu fei]
I suggest you check column size in function `validateInsert `, for example, 
should check row column size of insert should not less than size of select. see 
the patch
 [^1.patch] 

and you will get error information as below:
```java
org.apache.calcite.tools.ValidationException: 
java.lang.IllegalArgumentException: Insert column size(1) should not less than 
that of select column(2)
at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:196)
at com.netease.yuqi.calcatetest.TestTwo.main(TestTwo.java:46)
Caused by: java.lang.IllegalArgumentException: Insert column size(1) should not 
less than that of select column(2)
at 
com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3188)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert(SqlValidatorImpl.java:4175)
at org.apache.calcite.sql.SqlInsert.validate(SqlInsert.java:148)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:915)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:625)
at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:194)
... 1 more
```



> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
> Attachments: 1.patch
>
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I 

[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-31 Thread Fei Xu (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496143#comment-16496143
 ] 

Fei Xu commented on CALCITE-2336:
-

Well, would you please execute the following unit test in 
org.apache.calcite.test.InterpreterTest to verify ?, I found the problem when I 
use calcite in my own application. So I write a temporary test case.
{code:java}
  @Test public void testIndexOutOfBoundsException() throws Exception {
rootSchema = Frameworks.createRootSchema(true);

rootSchema.add("USERS", new AbstractTable() {
  @Override public RelDataType getRowType(final RelDataTypeFactory 
typeFactory) {
RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
//builder.add("name", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
SqlTypeName.BIGINT));
builder.add("name", typeFactory.createSqlType(SqlTypeName.INTEGER));
return builder.build();
  }
});

final FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(rootSchema)
.build();
planner = Frameworks.getPlanner(config);
dataContext = new MyDataContext(planner);

SqlNode parse =
planner.parse("insert into users select y, x\n"
+ "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
+ "where x > 1");

SqlNode validate = planner.validate(parse);
//RelNode convert = planner.rel(validate).rel;

//final Interpreter interpreter = new Interpreter(dataContext, convert);
//assertRows(interpreter, "[0]", "[10]", "[20]", "[30]");
  }
{code}
 

> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && 

[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-30 Thread Julian Hyde (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496093#comment-16496093
 ] 

Julian Hyde commented on CALCITE-2336:
--

In which case, sorry, I have no idea.

> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I get what I need.
> {code:java}
> && targetRowType.getFieldCount() - 1 >= i  
> ? targetRowType.getFieldList().get(i).getType(){code}
> So is this a Bug ? Do we need fix it ? 
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-30 Thread Fei Xu (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496013#comment-16496013
 ] 

Fei Xu commented on CALCITE-2336:
-

Hi Julian, I change the code, e.g. but it seems doesn't help.

 
{code:java}
rootSchema = Frameworks.createRootSchema(true);

rootSchema.add("USERS", new AbstractTable() {
  @Override public RelDataType getRowType(final RelDataTypeFactory 
typeFactory) {
RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
//builder.add("name", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
SqlTypeName.BIGINT));
builder.add("name", typeFactory.createSqlType(SqlTypeName.BIGINT));
return builder.build();
  }
});

final FrameworkConfig config = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(rootSchema)
.build();
planner = Frameworks.getPlanner(config);
dataContext = new MyDataContext(planner);

SqlNode parse =
planner.parse("insert into users select y, x\n"
+ "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
+ "where x > 1");

SqlNode validate = planner.validate(parse);
RelNode convert = planner.rel(validate).rel;
{code}
I still get the message 

 

 
{code:java}
Caused by: java.lang.IndexOutOfBoundsException: index (1) must be less than 
size (1)
at 
com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
at 
com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
at 
com.google.common.collect.SingletonImmutableList.get(SingletonImmutableList.java:41)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:3993)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3251)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert(SqlValidatorImpl.java:4165)
at org.apache.calcite.sql.SqlInsert.validate(SqlInsert.java:148)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:915)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:625)
at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:194)
... 25 more
{code}
 

 

 

 

> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   

[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-30 Thread Fei Xu (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16495941#comment-16495941
 ] 

Fei Xu commented on CALCITE-2336:
-

thanks julian,I’ll try this way


Julian Hyde (JIRA) 于2018年5月31日 周四上午6:31写道:



> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I get what I need.
> {code:java}
> && targetRowType.getFieldCount() - 1 >= i  
> ? targetRowType.getFieldList().get(i).getType(){code}
> So is this a Bug ? Do we need fix it ? 
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-30 Thread Julian Hyde (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16495809#comment-16495809
 ] 

Julian Hyde commented on CALCITE-2336:
--

Try replacing {{new BasicSqlType}} with a method call into the type factory. We 
rely on types being canonized.

> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I get what I need.
> {code:java}
> && targetRowType.getFieldCount() - 1 >= i  
> ? targetRowType.getFieldList().get(i).getType(){code}
> So is this a Bug ? Do we need fix it ? 
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)