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))); } } }
names = Lists.transform(names, s -> s.toUpperCase(Locale.ROOT)); final int duplicateAliasOrdinal = Util.firstDuplicate(names); if (duplicateAliasOrdinal >= 0) { final ScopeChild child =
/** * Returns whether the elements of {@code list} are distinct. */ public static <E> boolean isDistinct(List<E> list) { return firstDuplicate(list) < 0; }
/** * Returns whether the elements of {@code list} are distinct. */ public static <E> boolean isDistinct(List<E> list) { return firstDuplicate(list) < 0; }
/** * Checks that there are no duplicates in a list of {@link SqlIdentifier}. */ static void checkIdentifierListForDuplicates(List<SqlNode> columnList, SqlValidatorImpl.ValidationErrorFunction validationErrorFunction) { final List<List<String>> names = Lists.transform(columnList, o -> ((SqlIdentifier) o).names); final int i = Util.firstDuplicate(names); if (i >= 0) { throw validationErrorFunction.apply(columnList.get(i), RESOURCE.duplicateNameInColumnList(Util.last(names.get(i)))); } }
/** * Checks that there are no duplicates in a list of {@link SqlIdentifier}. */ static void checkIdentifierListForDuplicates(List<SqlNode> columnList, SqlValidatorImpl.ValidationErrorFunction validationErrorFunction) { final List<List<String>> names = Lists.transform(columnList, o -> ((SqlIdentifier) o).names); final int i = Util.firstDuplicate(names); if (i >= 0) { throw validationErrorFunction.apply(columnList.get(i), RESOURCE.duplicateNameInColumnList(Util.last(names.get(i)))); } }
/** Unit test for {@link Util#firstDuplicate(java.util.List)}. */ @Test public void testFirstDuplicate() { assertThat(Util.firstDuplicate(ImmutableList.of()), equalTo(-1)); assertThat(Util.firstDuplicate(ImmutableList.of(5)), equalTo(-1)); assertThat(Util.firstDuplicate(ImmutableList.of(5, 6)), equalTo(-1)); assertThat(Util.firstDuplicate(ImmutableList.of(5, 6, 5)), equalTo(2)); assertThat(Util.firstDuplicate(ImmutableList.of(5, 5, 6)), equalTo(1)); assertThat(Util.firstDuplicate(ImmutableList.of(5, 5, 6, 5)), equalTo(1)); // list longer than 15, the threshold where we move to set-based algorithm assertThat( Util.firstDuplicate( ImmutableList.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 3, 19, 3, 21)), equalTo(18)); }
/** Unit test for {@link Util#firstDuplicate(java.util.List)}. */ @Test public void testFirstDuplicate() { assertThat(Util.firstDuplicate(ImmutableList.of()), equalTo(-1)); assertThat(Util.firstDuplicate(ImmutableList.of(5)), equalTo(-1)); assertThat(Util.firstDuplicate(ImmutableList.of(5, 6)), equalTo(-1)); assertThat(Util.firstDuplicate(ImmutableList.of(5, 6, 5)), equalTo(2)); assertThat(Util.firstDuplicate(ImmutableList.of(5, 5, 6)), equalTo(1)); assertThat(Util.firstDuplicate(ImmutableList.of(5, 5, 6, 5)), equalTo(1)); // list longer than 15, the threshold where we move to set-based algorithm assertThat( Util.firstDuplicate( ImmutableList.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 3, 19, 3, 21)), equalTo(18)); }
protected List<SqlNode> constructOperandList( SqlValidator validator, SqlCall call, List<String> argNames) { if (argNames == null) { return call.getOperandList(); } if (argNames.size() < call.getOperandList().size()) { throw validator.newValidationError(call, RESOURCE.someButNotAllArgumentsAreNamed()); } final int duplicate = Util.firstDuplicate(argNames); if (duplicate >= 0) { throw validator.newValidationError(call, RESOURCE.duplicateArgumentName(argNames.get(duplicate))); } final ImmutableList.Builder<SqlNode> argBuilder = ImmutableList.builder(); for (SqlNode operand : call.getOperandList()) { if (operand.getKind() == SqlKind.ARGUMENT_ASSIGNMENT) { final List<SqlNode> operandList = ((SqlCall) operand).getOperandList(); argBuilder.add(operandList.get(0)); } } return argBuilder.build(); }
protected List<SqlNode> constructOperandList( SqlValidator validator, SqlCall call, List<String> argNames) { if (argNames == null) { return call.getOperandList(); } if (argNames.size() < call.getOperandList().size()) { throw validator.newValidationError(call, RESOURCE.someButNotAllArgumentsAreNamed()); } final int duplicate = Util.firstDuplicate(argNames); if (duplicate >= 0) { throw validator.newValidationError(call, RESOURCE.duplicateArgumentName(argNames.get(duplicate))); } final ImmutableList.Builder<SqlNode> argBuilder = ImmutableList.builder(); for (SqlNode operand : call.getOperandList()) { if (operand.getKind() == SqlKind.ARGUMENT_ASSIGNMENT) { final List<SqlNode> operandList = ((SqlCall) operand).getOperandList(); argBuilder.add(operandList.get(0)); } } return argBuilder.build(); }
int n = 0; for (int j = 0; j < limit; j++) { n += Util.firstDuplicate(lists.get(j % zMax));
int n = 0; for (int j = 0; j < limit; j++) { n += Util.firstDuplicate(lists.get(j % zMax));
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))); } } }
names = Lists.transform(names, s -> s.toUpperCase(Locale.ROOT)); final int duplicateAliasOrdinal = Util.firstDuplicate(names); if (duplicateAliasOrdinal >= 0) { final ScopeChild child =
names = Lists.transform(names, s -> s.toUpperCase(Locale.ROOT)); final int duplicateAliasOrdinal = Util.firstDuplicate(names); if (duplicateAliasOrdinal >= 0) { final ScopeChild child =