org.apache.calcite.util.Util.firstDuplicate()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中org.apache.calcite.util.Util.firstDuplicate()方法的一些代码示例,展示了Util.firstDuplicate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.firstDuplicate()方法的具体详情如下:
包路径:org.apache.calcite.util.Util
类名称:Util
方法名:firstDuplicate

Util.firstDuplicate介绍

[英]Returns the ordinal of the first element in the list which is equal to a previous element in the list.

For example, firstDuplicate(Arrays.asList("a", "b", "c", "b", "a")) returns 3, the ordinal of the 2nd "b".
[中]返回列表中第一个元素的序号,该序号等于列表中前一个元素的序号。
例如,firstDuplicate(Arrays.asList("a", "b", "c", "b", "a"))返回第二个“b”的序号3。

代码示例

代码示例来源:origin: apache/flink

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)));
    }
  }
}

代码示例来源:origin: apache/flink

names = Lists.transform(names, s -> s.toUpperCase(Locale.ROOT));
final int duplicateAliasOrdinal = Util.firstDuplicate(names);
if (duplicateAliasOrdinal >= 0) {
  final ScopeChild child =

代码示例来源:origin: Qihoo360/Quicksql

/**
 * Returns whether the elements of {@code list} are distinct.
 */
public static <E> boolean isDistinct(List<E> list) {
 return firstDuplicate(list) < 0;
}

代码示例来源:origin: org.apache.calcite/calcite-core

/**
 * Returns whether the elements of {@code list} are distinct.
 */
public static <E> boolean isDistinct(List<E> list) {
 return firstDuplicate(list) < 0;
}

代码示例来源:origin: Qihoo360/Quicksql

/**
 * 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))));
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

/**
 * 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))));
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

/** 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));
}

代码示例来源:origin: Qihoo360/Quicksql

/** 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));
}

代码示例来源:origin: org.apache.calcite/calcite-core

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();
}

代码示例来源:origin: Qihoo360/Quicksql

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();
}

代码示例来源:origin: Qihoo360/Quicksql

int n = 0;
for (int j = 0; j < limit; j++) {
 n += Util.firstDuplicate(lists.get(j % zMax));

代码示例来源:origin: org.apache.calcite/calcite-core

int n = 0;
for (int j = 0; j < limit; j++) {
 n += Util.firstDuplicate(lists.get(j % zMax));

代码示例来源:origin: Qihoo360/Quicksql

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)));
  }
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

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)));
  }
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

names = Lists.transform(names, s -> s.toUpperCase(Locale.ROOT));
final int duplicateAliasOrdinal = Util.firstDuplicate(names);
if (duplicateAliasOrdinal >= 0) {
 final ScopeChild child =

代码示例来源:origin: Qihoo360/Quicksql

names = Lists.transform(names, s -> s.toUpperCase(Locale.ROOT));
final int duplicateAliasOrdinal = Util.firstDuplicate(names);
if (duplicateAliasOrdinal >= 0) {
 final ScopeChild child =

相关文章