public void validateWithItem(SqlWithItem withItem) { if (withItem.columnList != null) { final RelDataType rowType = getValidatedNodeType(withItem.query); final int fieldCount = rowType.getFieldCount(); if (withItem.columnList.size() != fieldCount) { throw newValidationError(withItem.columnList, RESOURCE.columnCountMismatch()); } SqlValidatorUtil.checkIdentifierListForDuplicates( withItem.columnList.getList(), validationErrorFunction); } else { // Luckily, field names have not been make unique yet. final List<String> fieldNames = getValidatedNodeType(withItem.query).getFieldNames(); final int i = Util.firstDuplicate(fieldNames); if (i >= 0) { throw newValidationError(withItem.query, RESOURCE.duplicateColumnAndNoColumnList(fieldNames.get(i))); } } }
SqlValidatorUtil.checkIdentifierListForDuplicates( identifierList, validator.getValidationErrorFunction()); final ImmutableList.Builder<RelDataTypeField> builder =
@SuppressWarnings("resource") @Test public void testCheckingDuplicatesWithCompoundIdentifiers() { final List<SqlNode> newList = new ArrayList<>(2); newList.add(new SqlIdentifier(Arrays.asList("f0", "c0"), SqlParserPos.ZERO)); newList.add(new SqlIdentifier(Arrays.asList("f0", "c0"), SqlParserPos.ZERO)); final SqlTester tester = new SqlValidatorTester(SqlTestFactory.INSTANCE); final SqlValidatorImpl validator = (SqlValidatorImpl) tester.getValidator(); try { SqlValidatorUtil.checkIdentifierListForDuplicates(newList, validator.getValidationErrorFunction()); fail("expected exception"); } catch (CalciteContextException e) { // ok } // should not throw newList.set(1, new SqlIdentifier(Arrays.asList("f0", "c1"), SqlParserPos.ZERO)); SqlValidatorUtil.checkIdentifierListForDuplicates(newList, null); }
SqlValidatorUtil.checkIdentifierListForDuplicates( identifierList, validator.getValidationErrorFunction()); final ImmutableList.Builder<RelDataTypeField> builder =
@SuppressWarnings("resource") @Test public void testCheckingDuplicatesWithCompoundIdentifiers() { final List<SqlNode> newList = new ArrayList<>(2); newList.add(new SqlIdentifier(Arrays.asList("f0", "c0"), SqlParserPos.ZERO)); newList.add(new SqlIdentifier(Arrays.asList("f0", "c0"), SqlParserPos.ZERO)); final SqlTester tester = new SqlValidatorTester(SqlTestFactory.INSTANCE); final SqlValidatorImpl validator = (SqlValidatorImpl) tester.getValidator(); try { SqlValidatorUtil.checkIdentifierListForDuplicates(newList, validator.getValidationErrorFunction()); fail("expected exception"); } catch (CalciteContextException e) { // ok } // should not throw newList.set(1, new SqlIdentifier(Arrays.asList("f0", "c1"), SqlParserPos.ZERO)); SqlValidatorUtil.checkIdentifierListForDuplicates(newList, null); }
public void validateWithItem(SqlWithItem withItem) { if (withItem.columnList != null) { final RelDataType rowType = getValidatedNodeType(withItem.query); final int fieldCount = rowType.getFieldCount(); if (withItem.columnList.size() != fieldCount) { throw newValidationError(withItem.columnList, RESOURCE.columnCountMismatch()); } SqlValidatorUtil.checkIdentifierListForDuplicates( withItem.columnList.getList(), validationErrorFunction); } else { // Luckily, field names have not been make unique yet. final List<String> fieldNames = getValidatedNodeType(withItem.query).getFieldNames(); final int i = Util.firstDuplicate(fieldNames); if (i >= 0) { throw newValidationError(withItem.query, RESOURCE.duplicateColumnAndNoColumnList(fieldNames.get(i))); } } }
public void validateWithItem(SqlWithItem withItem) { if (withItem.columnList != null) { final RelDataType rowType = getValidatedNodeType(withItem.query); final int fieldCount = rowType.getFieldCount(); if (withItem.columnList.size() != fieldCount) { throw newValidationError(withItem.columnList, RESOURCE.columnCountMismatch()); } SqlValidatorUtil.checkIdentifierListForDuplicates( withItem.columnList.getList(), validationErrorFunction); } else { // Luckily, field names have not been make unique yet. final List<String> fieldNames = getValidatedNodeType(withItem.query).getFieldNames(); final int i = Util.firstDuplicate(fieldNames); if (i >= 0) { throw newValidationError(withItem.query, RESOURCE.duplicateColumnAndNoColumnList(fieldNames.get(i))); } } }