当前位置: 首页>>代码示例>>Java>>正文


Java Util.last方法代码示例

本文整理汇总了Java中org.apache.calcite.util.Util.last方法的典型用法代码示例。如果您正苦于以下问题:Java Util.last方法的具体用法?Java Util.last怎么用?Java Util.last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.util.Util的用法示例。


在下文中一共展示了Util.last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAlias

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/**
 * Derives an alias for a node, and invents a mangled identifier if it
 * cannot.
 *
 * <p>Examples:
 *
 * <ul>
 * <li>Alias: "1 + 2 as foo" yields "foo"
 * <li>Identifier: "foo.bar.baz" yields "baz"
 * <li>Anything else yields "expr$<i>ordinal</i>"
 * </ul>
 *
 * @return An alias, if one can be derived; or a synthetic alias
 * "expr$<i>ordinal</i>" if ordinal &lt; 0; otherwise null
 */
public static String getAlias(SqlNode node, int ordinal) {
  switch (node.getKind()) {
  case AS:
    // E.g. "1 + 2 as foo" --> "foo"
    return ((SqlCall) node).operand(1).toString();

  case OVER:
    // E.g. "bids over w" --> "bids"
    return getAlias(((SqlCall) node).operand(0), ordinal);

  case IDENTIFIER:
    // E.g. "foo.bar" --> "bar"
    return Util.last(((SqlIdentifier) node).names);

  default:
    if (ordinal < 0) {
      return null;
    } else {
      return SqlUtil.deriveAliasFromOrdinal(ordinal);
    }
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:38,代码来源:SqlValidatorUtil.java

示例2: intervalString

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
private String intervalString(BigDecimal v) {
  final List<TimeUnit> timeUnits = getTimeUnits(type.getSqlTypeName());
  final StringBuilder b = new StringBuilder();
  for (TimeUnit timeUnit : timeUnits) {
    final BigDecimal[] result = v.divideAndRemainder(timeUnit.multiplier);
    if (b.length() > 0) {
      b.append(timeUnit.separator);
    }
    final int width = b.length() == 0 ? -1 : width(timeUnit); // don't pad 1st
    pad(b, result[0].toString(), width);
    v = result[1];
  }
  if (Util.last(timeUnits) == TimeUnit.MILLISECOND) {
    while (b.toString().matches(".*\\.[0-9]*0")) {
      if (b.toString().endsWith(".0")) {
        b.setLength(b.length() - 2); // remove ".0"
      } else {
        b.setLength(b.length() - 1); // remove "0"
      }
    }
  }
  return b.toString();
}
 
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:RexLiteral.java

示例3: SqlUserDefinedAggFunction

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
public SqlUserDefinedAggFunction(SqlIdentifier opName,
                                 SqlReturnTypeInference returnTypeInference,
                                 SqlOperandTypeInference operandTypeInference,
                                 SqlOperandTypeChecker operandTypeChecker,
                                 AggregateFunction function,
                                 Boolean requestsOver) {
    super(Util.last(opName.names), opName, SqlKind.OTHER_FUNCTION,
          returnTypeInference, operandTypeInference, operandTypeChecker,
          SqlFunctionCategory.USER_DEFINED_FUNCTION, false, requestsOver);
    this.function = function;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:12,代码来源:SqlUserDefinedAggFunction.java

示例4: create

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
public static MySchemaPlus create(Path path) {
  final Pair<String, Schema> pair = Util.last(path);
  final SchemaPlus parent;
  if (path.size() == 1) {
    parent = null;
  } else {
    parent = create(path.parent());
  }
  return new MySchemaPlus(parent, pair.left, pair.right);
}
 
开发者ID:apache,项目名称:calcite,代码行数:11,代码来源:RelOptTableImpl.java

示例5: checkRollUpInUsing

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
private void checkRollUpInUsing(SqlIdentifier identifier, SqlNode leftOrRight) {
  leftOrRight = stripAs(leftOrRight);
  // if it's not a SqlIdentifier then that's fine, it'll be validated somewhere else.
  if (leftOrRight instanceof SqlIdentifier) {
    SqlIdentifier from = (SqlIdentifier) leftOrRight;
    Table table = findTable(catalogReader.getRootSchema(), Util.last(from.names),
            catalogReader.nameMatcher().isCaseSensitive());
    String name = Util.last(identifier.names);

    if (table != null && table.isRolledUp(name)) {
      throw newValidationError(identifier, RESOURCE.rolledUpNotAllowed(name, "USING"));
    }
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:15,代码来源:SqlValidatorImpl.java

示例6: findTableColumnPair

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
private Pair<String, String> findTableColumnPair(SqlIdentifier identifier,
                                                 SqlValidatorScope scope) {
  SqlCall call = SqlUtil.makeCall(getOperatorTable(), identifier);
  if (call != null) {
    return null;
  }
  SqlQualified qualified = scope.fullyQualify(identifier);
  List<String> names = qualified.identifier.names;

  if (names.size() < 2) {
    return null;
  }

  return new Pair<>(names.get(names.size() - 2), Util.last(names));
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:SqlValidatorImpl.java

示例7: findChild

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
private ScopeChild findChild(List<String> names,
    SqlNameMatcher nameMatcher) {
  for (ScopeChild child : children) {
    String lastName = Util.last(names);
    if (child.name != null) {
      if (!nameMatcher.matches(child.name, lastName)) {
        // Alias does not match last segment. Don't consider the
        // fully-qualified name. E.g.
        //    SELECT sales.emp.name FROM sales.emp AS otherAlias
        continue;
      }
      if (names.size() == 1) {
        return child;
      }
    }

    // Look up the 2 tables independently, in case one is qualified with
    // catalog & schema and the other is not.
    final SqlValidatorTable table = child.namespace.getTable();
    if (table != null) {
      final ResolvedImpl resolved = new ResolvedImpl();
      resolveTable(names, nameMatcher, Path.EMPTY, resolved);
      if (resolved.count() == 1
          && resolved.only().remainingNames.isEmpty()
          && resolved.only().namespace instanceof TableNamespace
          && resolved.only().namespace.getTable().getQualifiedName().equals(
              table.getQualifiedName())) {
        return child;
      }
    }
  }
  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:34,代码来源:ListScope.java

示例8: SqlUserDefinedAggFunction

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/** Creates a SqlUserDefinedAggFunction. */
public SqlUserDefinedAggFunction(SqlIdentifier opName,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker, AggregateFunction function,
    boolean requiresOrder, boolean requiresOver, RelDataTypeFactory typeFactory) {
  super(Util.last(opName.names), opName, SqlKind.OTHER_FUNCTION,
      returnTypeInference, operandTypeInference, operandTypeChecker,
      SqlFunctionCategory.USER_DEFINED_FUNCTION, requiresOrder, requiresOver);
  this.function = function;
  this.typeFactory = typeFactory;
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:SqlUserDefinedAggFunction.java

示例9: SqlUserDefinedTableMacro

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
public SqlUserDefinedTableMacro(SqlIdentifier opName,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker, List<RelDataType> paramTypes,
    TableMacro tableMacro) {
  super(Util.last(opName.names), opName, SqlKind.OTHER_FUNCTION,
      returnTypeInference, operandTypeInference, operandTypeChecker,
      Preconditions.checkNotNull(paramTypes),
      SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION);
  this.tableMacro = tableMacro;
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:SqlUserDefinedTableMacro.java

示例10: SqlUserDefinedFunction

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/** Constructor used internally and by derived classes. */
protected SqlUserDefinedFunction(SqlIdentifier opName,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker,
    List<RelDataType> paramTypes,
    Function function,
    SqlFunctionCategory category) {
  super(Util.last(opName.names), opName, SqlKind.OTHER_FUNCTION,
      returnTypeInference, operandTypeInference, operandTypeChecker,
      paramTypes, category);
  this.function = function;
}
 
开发者ID:apache,项目名称:calcite,代码行数:14,代码来源:SqlUserDefinedFunction.java

示例11: deriveAlias

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
private static String deriveAlias(RelNode rel) {
  if (rel instanceof TableScan) {
    final List<String> names = rel.getTable().getQualifiedName();
    if (!names.isEmpty()) {
      return Util.last(names);
    }
  }
  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:10,代码来源:RelBuilder.java

示例12: getAlias

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
String getAlias() {
  if (lastAlias != null) {
    return lastAlias;
  } else {
    RelNode top = peek();
    if (top instanceof TableScan) {
      return Util.last(top.getTable().getQualifiedName());
    } else {
      return null;
    }
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:PigRelBuilder.java

示例13: extend

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
@Override public Table extend(final List<RelDataTypeField> fields) {
  return new ModifiableTable(Util.last(names)) {
    @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) {
      ImmutableList<RelDataTypeField> allFields = ImmutableList.copyOf(
          Iterables.concat(
              ModifiableTable.this.getRowType(typeFactory).getFieldList(),
              fields));
      return typeFactory.createStructType(allFields);
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:MockCatalogReader.java

示例14: unwrap

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
public <T> T unwrap(Class<T> clazz) {
  if (clazz.isInstance(this)) {
    return clazz.cast(this);
  }
  if (clazz.isInstance(initializerFactory)) {
    return clazz.cast(initializerFactory);
  }
  if (clazz.isAssignableFrom(Table.class)) {
    final Table table = resolver == null
        ? new ModifiableTable(Util.last(names))
            : new ModifiableTableWithCustomColumnResolving(Util.last(names));
    return clazz.cast(table);
  }
  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:MockCatalogReader.java

示例15: rewrite

import org.apache.calcite.util.Util; //导入方法依赖的package包/类
/** Rewrite the parse tree as SELECT ... FROM INFORMATION_SCHEMA.COLUMNS ... */
@Override
public SqlNode rewrite(SqlNode sqlNode) throws RelConversionException, ForemanSetupException {
  SqlDescribeTable node = unwrap(sqlNode, SqlDescribeTable.class);

  try {
    List<SqlNode> selectList =
        ImmutableList.of((SqlNode) new SqlIdentifier(COLS_COL_COLUMN_NAME, SqlParserPos.ZERO),
                                   new SqlIdentifier(COLS_COL_DATA_TYPE, SqlParserPos.ZERO),
                                   new SqlIdentifier(COLS_COL_IS_NULLABLE, SqlParserPos.ZERO));

    SqlNode fromClause = new SqlIdentifier(
        ImmutableList.of(IS_SCHEMA_NAME, TAB_COLUMNS), null, SqlParserPos.ZERO, null);

    final SqlIdentifier table = node.getTable();
    final SchemaPlus defaultSchema = context.getNewDefaultSchema();
    final List<String> schemaPathGivenInCmd = Util.skipLast(table.names);
    final SchemaPlus schema = SchemaUtilites.findSchema(defaultSchema, schemaPathGivenInCmd);

    if (schema == null) {
      SchemaUtilites.throwSchemaNotFoundException(defaultSchema,
          SchemaUtilites.SCHEMA_PATH_JOINER.join(schemaPathGivenInCmd));
    }

    if (SchemaUtilites.isRootSchema(schema)) {
      throw UserException.validationError()
          .message("No schema selected.")
          .build(logger);
    }

    final String tableName = Util.last(table.names);

    // find resolved schema path
    final String schemaPath = SchemaUtilites.unwrapAsDrillSchemaInstance(schema).getFullSchemaName();

    if (schema.getTable(tableName) == null) {
      throw UserException.validationError()
          .message("Unknown table [%s] in schema [%s]", tableName, schemaPath)
          .build(logger);
    }

    SqlNode schemaCondition = null;
    if (!SchemaUtilites.isRootSchema(schema)) {
      schemaCondition = DrillParserUtil.createCondition(
          new SqlIdentifier(SHRD_COL_TABLE_SCHEMA, SqlParserPos.ZERO),
          SqlStdOperatorTable.EQUALS,
          SqlLiteral.createCharString(schemaPath, CHARSET, SqlParserPos.ZERO)
      );
    }

    SqlNode where = DrillParserUtil.createCondition(
        new SqlIdentifier(SHRD_COL_TABLE_NAME, SqlParserPos.ZERO),
        SqlStdOperatorTable.EQUALS,
        SqlLiteral.createCharString(tableName, CHARSET, SqlParserPos.ZERO));

    where = DrillParserUtil.createCondition(schemaCondition, SqlStdOperatorTable.AND, where);

    SqlNode columnFilter = null;
    if (node.getColumn() != null) {
      columnFilter =
          DrillParserUtil.createCondition(
              new SqlIdentifier(COLS_COL_COLUMN_NAME, SqlParserPos.ZERO),
              SqlStdOperatorTable.EQUALS,
              SqlLiteral.createCharString(node.getColumn().toString(), CHARSET, SqlParserPos.ZERO));
    } else if (node.getColumnQualifier() != null) {
      columnFilter =
          DrillParserUtil.createCondition(
              new SqlIdentifier(COLS_COL_COLUMN_NAME, SqlParserPos.ZERO),
              SqlStdOperatorTable.LIKE, node.getColumnQualifier());
    }

    where = DrillParserUtil.createCondition(where, SqlStdOperatorTable.AND, columnFilter);

    return new SqlSelect(SqlParserPos.ZERO, null, new SqlNodeList(selectList, SqlParserPos.ZERO),
        fromClause, where, null, null, null, null, null, null);
  } catch (Exception ex) {
    throw UserException.planError(ex)
        .message("Error while rewriting DESCRIBE query: %d", ex.getMessage())
        .build(logger);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:82,代码来源:DescribeTableHandler.java


注:本文中的org.apache.calcite.util.Util.last方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。