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

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

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

Util.skipLast介绍

[英]Returns every element of a list but its last element.
[中]返回列表中除最后一个元素外的所有元素。

代码示例

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

Collection<SqlMoniker> hintList) {
List<String> subNames = Util.skipLast(names);

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

/** Returns every element of a list but its last element. */
public static <E> List<E> skipLast(List<E> list) {
 return skipLast(list, 1);
}

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

/** Returns every element of a list but its last element. */
public static <E> List<E> skipLast(List<E> list) {
 return skipLast(list, 1);
}

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

public static void getSchemaObjectMonikers(
  SqlValidatorCatalogReader catalogReader,
  List<String> names,
  List<SqlMoniker> hints) {
 // Assume that the last name is 'dummy' or similar.
 List<String> subNames = Util.skipLast(names);
 // Try successively with catalog.schema, catalog and no prefix
 for (List<String> x : catalogReader.getSchemaPaths()) {
  final List<String> names2 =
    ImmutableList.<String>builder().addAll(x).addAll(subNames).build();
  hints.addAll(catalogReader.getAllSchemaObjectNames(names2));
 }
}

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

public static void getSchemaObjectMonikers(
  SqlValidatorCatalogReader catalogReader,
  List<String> names,
  List<SqlMoniker> hints) {
 // Assume that the last name is 'dummy' or similar.
 List<String> subNames = Util.skipLast(names);
 // Try successively with catalog.schema, catalog and no prefix
 for (List<String> x : catalogReader.getSchemaPaths()) {
  final List<String> names2 =
    ImmutableList.<String>builder().addAll(x).addAll(subNames).build();
  hints.addAll(catalogReader.getAllSchemaObjectNames(names2));
 }
}

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

public <T> T unwrap(Class<T> clazz) {
 if (clazz.isInstance(this)) {
  return clazz.cast(this);
 }
 if (clazz.isInstance(table)) {
  return clazz.cast(table);
 }
 if (table instanceof Wrapper) {
  final T t = ((Wrapper) table).unwrap(clazz);
  if (t != null) {
   return t;
  }
 }
 if (clazz == CalciteSchema.class) {
  return clazz.cast(
    Schemas.subSchema(((CalciteCatalogReader) schema).rootSchema,
      Util.skipLast(getQualifiedName())));
 }
 return null;
}

代码示例来源:origin: qubole/quark

private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) {
 if (nodeList.size() == 2) {
  return op.createCall(new SqlNodeList(nodeList, POS));
 }
 final List<SqlNode> butLast = Util.skipLast(nodeList);
 final SqlNode last = nodeList.get(nodeList.size() - 1);
 final SqlNode call = createLeftCall(op, butLast);
 return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS));
}

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

private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) {
 if (nodeList.size() == 2) {
  return op.createCall(new SqlNodeList(nodeList, POS));
 }
 final List<SqlNode> butLast = Util.skipLast(nodeList);
 final SqlNode last = nodeList.get(nodeList.size() - 1);
 final SqlNode call = createLeftCall(op, butLast);
 return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS));
}

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

public <T> T unwrap(Class<T> clazz) {
 if (clazz.isInstance(this)) {
  return clazz.cast(this);
 }
 if (clazz.isInstance(table)) {
  return clazz.cast(table);
 }
 if (table instanceof Wrapper) {
  final T t = ((Wrapper) table).unwrap(clazz);
  if (t != null) {
   return t;
  }
 }
 if (clazz == CalciteSchema.class) {
  return clazz.cast(
    Schemas.subSchema(((CalciteCatalogReader) schema).rootSchema,
      Util.skipLast(getQualifiedName())));
 }
 return null;
}

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

private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) {
 if (nodeList.size() == 2) {
  return op.createCall(new SqlNodeList(nodeList, POS));
 }
 final List<SqlNode> butLast = Util.skipLast(nodeList);
 final SqlNode last = nodeList.get(nodeList.size() - 1);
 final SqlNode call = createLeftCall(op, butLast);
 return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS));
}

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

/** Creates a call that concatenates patterns;
 * for use in {@link #match}. */
public RexNode patternConcat(Iterable<? extends RexNode> nodes) {
 final ImmutableList<RexNode> list = ImmutableList.copyOf(nodes);
 if (list.size() > 2) {
  // Convert into binary calls
  return patternConcat(patternConcat(Util.skipLast(list)), Util.last(list));
 }
 final RelDataType t = getTypeFactory().createSqlType(SqlTypeName.NULL);
 return getRexBuilder().makeCall(t, SqlStdOperatorTable.PATTERN_CONCAT,
   list);
}

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

/** Creates a call that concatenates patterns;
 * for use in {@link #match}. */
public RexNode patternConcat(Iterable<? extends RexNode> nodes) {
 final ImmutableList<RexNode> list = ImmutableList.copyOf(nodes);
 if (list.size() > 2) {
  // Convert into binary calls
  return patternConcat(patternConcat(Util.skipLast(list)), Util.last(list));
 }
 final RelDataType t = getTypeFactory().createSqlType(SqlTypeName.NULL);
 return getRexBuilder().makeCall(t, SqlStdOperatorTable.PATTERN_CONCAT,
   list);
}

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

private void registerTable(final List<String> names, final Table table) {
 assert names.get(0).equals(DEFAULT_CATALOG);
 final List<String> schemaPath = Util.skipLast(names);
 final String tableName = Util.last(names);
 final CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema,
   schemaPath, SqlNameMatchers.withCaseSensitive(true));
 schema.add(tableName, table);
}

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

protected void registerType(final List<String> names, final RelProtoDataType relProtoDataType) {
  assert names.get(0).equals(DEFAULT_CATALOG);
  final List<String> schemaPath = Util.skipLast(names);
  final CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema,
      schemaPath, SqlNameMatchers.withCaseSensitive(true));
  schema.add(Util.last(names), relProtoDataType);
}

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

private void registerTable(final List<String> names, final Table table) {
  assert names.get(0).equals(DEFAULT_CATALOG);
  final List<String> schemaPath = Util.skipLast(names);
  final String tableName = Util.last(names);
  final CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema,
      schemaPath, SqlNameMatchers.withCaseSensitive(true));
  schema.add(tableName, table);
}

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

protected void registerType(final List<String> names, final RelProtoDataType relProtoDataType) {
 assert names.get(0).equals(DEFAULT_CATALOG);
 final List<String> schemaPath = Util.skipLast(names);
 final CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema,
   schemaPath, SqlNameMatchers.withCaseSensitive(true));
 schema.add(Util.last(names), relProtoDataType);
}

代码示例来源:origin: org.apache.drill.exec/drill-java-exec

/**
 * check if the schema provided is a valid schema:
 * <li>schema is not indicated (only one element in the names list)<li/>
 *
 * @param names list of schema and table names, table name is always the last element
 * @throws UserException if the schema is not valid.
 */
private void isValidSchema(final List<String> names) throws UserException {
 SchemaPlus defaultSchema = session.getDefaultSchema(this.rootSchema);
 String defaultSchemaCombinedPath = SchemaUtilites.getSchemaPath(defaultSchema);
 List<String> schemaPath = Util.skipLast(names);
 String schemaPathCombined = SchemaUtilites.getSchemaPath(schemaPath);
 String commonPrefix = SchemaUtilites.getPrefixSchemaPath(defaultSchemaCombinedPath,
     schemaPathCombined,
     parserConfig.caseSensitive());
 boolean isPrefixDefaultPath = commonPrefix.length() == defaultSchemaCombinedPath.length();
 List<String> fullSchemaPath = Strings.isNullOrEmpty(defaultSchemaCombinedPath) ? schemaPath :
     isPrefixDefaultPath ? schemaPath : ListUtils.union(SchemaUtilites.getSchemaPathAsList(defaultSchema), schemaPath);
 if (names.size() > 1 && (SchemaUtilites.findSchema(this.rootSchema, fullSchemaPath) == null &&
     SchemaUtilites.findSchema(this.rootSchema, schemaPath) == null)) {
  SchemaUtilites.throwSchemaNotFoundException(defaultSchema, schemaPath);
 }
}

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

/**
 * Finds a {@link org.apache.calcite.jdbc.CalciteSchema.TypeEntry} in a
 * given schema whose type has the given name, possibly qualified.
 *
 * @param rootSchema root schema
 * @param typeName name of the type, may be qualified or fully-qualified
 *
 * @return TypeEntry with a table with the given name, or null
 */
public static CalciteSchema.TypeEntry getTypeEntry(
  CalciteSchema rootSchema, SqlIdentifier typeName) {
 final String name;
 final List<String> path;
 if (typeName.isSimple()) {
  path = ImmutableList.of();
  name = typeName.getSimple();
 } else {
  path = Util.skipLast(typeName.names);
  name = Util.last(typeName.names);
 }
 CalciteSchema schema = rootSchema;
 for (String p : path) {
  if (schema == rootSchema
    && SqlNameMatchers.withCaseSensitive(true).matches(p, schema.getName())) {
   continue;
  }
  schema = schema.getSubSchema(p, true);
 }
 return schema == null ? null : schema.getType(name, false);
}

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

public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
  validateQuantifier(validator, call); // check DISTINCT/ALL

  List<SqlNode> operands = call.getOperandList();

  if (operands.size() == 1) {
   // No CASE needed
   return operands.get(0);
  }

  SqlParserPos pos = call.getParserPosition();

  SqlNodeList whenList = new SqlNodeList(pos);
  SqlNodeList thenList = new SqlNodeList(pos);

  // todo: optimize when know operand is not null.

  for (SqlNode operand : Util.skipLast(operands)) {
   whenList.add(
     SqlStdOperatorTable.IS_NOT_NULL.createCall(pos, operand));
   thenList.add(SqlNode.clone(operand));
  }
  SqlNode elseExpr = Util.last(operands);
  assert call.getFunctionQuantifier() == null;
  return SqlCase.createSwitched(pos, null, whenList, thenList, elseExpr);
 }
}

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

public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
  validateQuantifier(validator, call); // check DISTINCT/ALL

  List<SqlNode> operands = call.getOperandList();

  if (operands.size() == 1) {
   // No CASE needed
   return operands.get(0);
  }

  SqlParserPos pos = call.getParserPosition();

  SqlNodeList whenList = new SqlNodeList(pos);
  SqlNodeList thenList = new SqlNodeList(pos);

  // todo: optimize when know operand is not null.

  for (SqlNode operand : Util.skipLast(operands)) {
   whenList.add(
     SqlStdOperatorTable.IS_NOT_NULL.createCall(pos, operand));
   thenList.add(SqlNode.clone(operand));
  }
  SqlNode elseExpr = Util.last(operands);
  assert call.getFunctionQuantifier() == null;
  return SqlCase.createSwitched(pos, null, whenList, thenList, elseExpr);
 }
}

相关文章