本文整理汇总了Java中org.apache.calcite.sql.SqlKind类的典型用法代码示例。如果您正苦于以下问题:Java SqlKind类的具体用法?Java SqlKind怎么用?Java SqlKind使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SqlKind类属于org.apache.calcite.sql包,在下文中一共展示了SqlKind类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDistributionMap
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
private Map<Integer, Integer> getDistributionMap(DrillProjectRel project) {
Map<Integer, Integer> m = new HashMap<Integer, Integer>();
for (Ord<RexNode> node : Ord.zip(project.getProjects())) {
// For distribution, either $0 or cast($0 as ...) would keep the distribution after projection.
if (node.e instanceof RexInputRef) {
m.put( ((RexInputRef) node.e).getIndex(), node.i);
} else if (node.e.isA(SqlKind.CAST)) {
RexNode operand = ((RexCall) node.e).getOperands().get(0);
if (operand instanceof RexInputRef) {
m.put(((RexInputRef) operand).getIndex(), node.i);
}
}
}
return m;
}
示例2: computeSelfCost
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery relMetadataQuery) {
for (AggregateCall aggCall : getAggCallList()) {
// For avg, stddev_pop, stddev_samp, var_pop and var_samp, the ReduceAggregatesRule is supposed
// to convert them to use sum and count. Here, we make the cost of the original functions high
// enough such that the planner does not choose them and instead chooses the rewritten functions.
if (aggCall.getAggregation().getKind() == SqlKind.AVG
|| aggCall.getAggregation().getKind() == SqlKind.STDDEV_SAMP
|| aggCall.getAggregation().getKind() == SqlKind.STDDEV_POP
|| aggCall.getAggregation().getKind() == SqlKind.VAR_POP
|| aggCall.getAggregation().getKind() == SqlKind.VAR_SAMP) {
return planner.getCostFactory().makeHugeCost();
}
}
final double rowCount = relMetadataQuery.getRowCount(this);
final double childRowCount = relMetadataQuery.getRowCount(this.getInput());
// Aggregates with more aggregate functions cost a bit more
float multiplier = 1f + (float) aggCalls.size() * 0.125f;
return ((Factory) planner.getCostFactory()).makeCost(rowCount,childRowCount * multiplier * DremioCost.FUNC_CPU_COST, 0, 0);
}
示例3: buildJoinConditions
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
/**
* Build the list of join conditions for this join.
* A join condition is built only for equality and IS NOT DISTINCT FROM comparisons. The difference is:
* null == null is FALSE whereas null IS NOT DISTINCT FROM null is TRUE
* For a use case of the IS NOT DISTINCT FROM comparison, see
* {@link org.apache.calcite.rel.rules.RemoveDistinctAggregateRule}
* @param conditions populated list of join conditions
* @param leftFields join fields from the left input
* @param rightFields join fields from the right input
*/
protected void buildJoinConditions(List<JoinCondition> conditions,
List<String> leftFields,
List<String> rightFields,
List<Integer> leftKeys,
List<Integer> rightKeys) {
List<RexNode> conjuncts = RelOptUtil.conjunctions(this.getCondition());
short i=0;
for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
final RexNode conditionExpr = conjuncts.get(i++);
final SqlKind kind = conditionExpr.getKind();
if (kind != SqlKind.EQUALS && kind != SqlKind.IS_NOT_DISTINCT_FROM) {
throw UserException.unsupportedError()
.message("Unsupported comparator in join condition %s", conditionExpr)
.build(logger);
}
conditions.add(new JoinCondition(kind.toString(),
FieldReference.getWithQuotedRef(leftFields.get(pair.left)),
FieldReference.getWithQuotedRef(rightFields.get(pair.right))));
}
}
示例4: getDistributionMap
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
private Map<Integer, Integer> getDistributionMap(ProjectRel project) {
Map<Integer, Integer> m = new HashMap<Integer, Integer>();
for (Ord<RexNode> node : Ord.zip(project.getProjects())) {
// For distribution, either $0 or cast($0 as ...) would keep the distribution after projection.
if (node.e instanceof RexInputRef) {
m.put( ((RexInputRef) node.e).getIndex(), node.i);
} else if (node.e.isA(SqlKind.CAST)) {
RexNode operand = ((RexCall) node.e).getOperands().get(0);
if (operand instanceof RexInputRef) {
m.put(((RexInputRef) operand).getIndex(), node.i);
}
}
}
return m;
}
示例5: SqlDatePartOperator
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
public SqlDatePartOperator() {
super(
"DATE_PART",
SqlKind.OTHER_FUNCTION,
ReturnTypes.BIGINT_NULLABLE,
null,
OperandTypes.sequence(
"<PERIOD LITERAL>, <DATE or TIMESTAMP or INTERVAL>",
new EnumeratedListChecker(VALID_PERIODS.keySet()),
OperandTypes.or(
OperandTypes.family(SqlTypeFamily.DATE),
OperandTypes.family(SqlTypeFamily.TIMESTAMP),
OperandTypes.family(SqlTypeFamily.DATETIME),
OperandTypes.family(SqlTypeFamily.DATETIME_INTERVAL),
OperandTypes.family(SqlTypeFamily.INTERVAL_DAY_TIME),
OperandTypes.family(SqlTypeFamily.INTERVAL_YEAR_MONTH))
),
SqlFunctionCategory.SYSTEM);
}
示例6: isSimpleColumnSelection
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
public static boolean isSimpleColumnSelection(Project project) {
HashSet<Integer> inputRefReferenced = new HashSet<>();
for (Pair<RexNode, String> proj : project.getNamedProjects()) {
if (proj.getKey().getKind() != SqlKind.INPUT_REF) {
return false;
}
RexInputRef inputRef = (RexInputRef) proj.getKey();
// If the input reference is again referenced, then it is not a simple column selection (since it is not a permutation).
if (inputRefReferenced.contains(inputRef.getIndex())) {
return false;
}
final String nameOfProjectField = proj.getValue();
final String nameOfInput = project.getInput().getRowType().getFieldNames().get(inputRef.getIndex());
// Renaming a column is not a simple column selection
if (nameOfProjectField == null || !nameOfProjectField.equals(nameOfInput)) {
return false;
}
inputRefReferenced.add(inputRef.getIndex());
}
return true;
}
示例7: RangeQueryInput
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
public RangeQueryInput(Object value, SqlKind type) {
this.min = this.max = value;
this.includeMax = this.includeMin = false;
switch (type) {
case GREATER_THAN:
this.max = null;
break;
case GREATER_THAN_OR_EQUAL:
this.max = null;
this.includeMin = true;
break;
case LESS_THAN:
this.min = null;
break;
case LESS_THAN_OR_EQUAL:
this.min = null;
this.includeMax = true;
break;
case EQUALS:
this.includeMax = this.includeMin = true;
break;
default:
throw new UnsupportedOperationException("Invalid kind " + type);
}
}
示例8: halfTree
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
@Test
public void halfTree(){
final RexNode node =
builder.makeCall(SqlStdOperatorTable.AND,
builder.makeCall(SqlStdOperatorTable.EQUALS,
builder.makeInputRef(factory.createSqlType(SqlTypeName.BIGINT), 0),
builder.makeBigintLiteral(BigDecimal.ONE)
),
builder.makeApproxLiteral(BigDecimal.ONE)
);
FindSimpleFilters finder = new FindSimpleFilters(builder);
StateHolder holder = node.accept(finder);
ImmutableList<RexCall> conditions = holder.getConditions();
assertEquals(1, conditions.size());
assertEquals(SqlKind.EQUALS, conditions.get(0).getKind());
assertEquals(SqlKind.LITERAL, holder.getNode().getKind());
assertTrue(holder.hasRemainingExpression());
}
示例9: doubleAnd
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
@Test
public void doubleAnd(){
final RexNode node =
builder.makeCall(SqlStdOperatorTable.AND,
builder.makeCall(SqlStdOperatorTable.EQUALS,
builder.makeInputRef(factory.createSqlType(SqlTypeName.BIGINT), 0),
builder.makeBigintLiteral(BigDecimal.ONE)
),
builder.makeCall(SqlStdOperatorTable.EQUALS,
builder.makeInputRef(factory.createSqlType(SqlTypeName.BIGINT), 0),
builder.makeBigintLiteral(BigDecimal.ONE)
)
);
FindSimpleFilters finder = new FindSimpleFilters(builder);
StateHolder holder = node.accept(finder);
ImmutableList<RexCall> conditions = holder.getConditions();
assertEquals(2, conditions.size());
assertEquals(SqlKind.EQUALS, conditions.get(0).getKind());
assertEquals(SqlKind.EQUALS, conditions.get(1).getKind());
assertFalse(holder.hasRemainingExpression());
}
示例10: equalityWithCast
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
@Test
public void equalityWithCast(){
final RexNode node = builder.makeCall(SqlStdOperatorTable.EQUALS,
builder.makeCast(
factory.createSqlType(SqlTypeName.ANY),
builder.makeBigintLiteral(BigDecimal.ONE)
),
builder.makeInputRef(factory.createSqlType(SqlTypeName.BIGINT), 0)
);
FindSimpleFilters finder = new FindSimpleFilters(builder);
StateHolder holder = node.accept(finder);
ImmutableList<RexCall> conditions = holder.getConditions();
assertEquals(1, conditions.size());
assertEquals(SqlKind.EQUALS, conditions.get(0).getKind());
// Make sure CAST was removed
assertEquals(SqlKind.LITERAL, conditions.get(0).getOperands().get(0).getKind());
assertFalse(holder.hasRemainingExpression());
}
示例11: extractAS
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
private static ASNode extractAS(SqlCall call) {
if (call.getOperator().getKind() == SqlKind.AS) {
List<SqlNode> operandList = call.getOperandList();
if (operandList.size() == 2) {
SqlNode exp = operandList.get(0);
SqlNode colID = operandList.get(1);
if (isSimpleID(colID)) {
return new ASNode((SqlIdentifier)colID, exp);
} else {
throw new UnsupportedOperationException("Unexpected AS " + colID + "\n" + SqlNodes.toTreeString(call));
}
} else {
throw new UnsupportedOperationException("Unexpected AS operands in field: \n" + SqlNodes.toTreeString(call));
}
}
throw new UnsupportedOperationException("AS not understood: " + SqlNodes.toSQLString(call));
}
示例12: visit
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
@Override public Void visit(SqlCall call) {
// ignore window aggregates and ranking functions (associated with OVER operator)
if (call.getOperator().getKind() == SqlKind.OVER) {
return null;
}
if (call.getOperator().isAggregator()) {
list.add(call);
return null;
}
// Don't traverse into sub-queries, even if they contain aggregate
// functions.
if (call instanceof SqlSelect) {
return null;
}
return call.getOperator().acceptCall(this, call);
}
示例13: auxiliaryToGroup
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
/** Returns the group function for which a given kind is an auxiliary
* function, or null if it is not an auxiliary function. */
public static SqlGroupFunction auxiliaryToGroup(SqlKind kind) {
switch (kind) {
case TUMBLE_START:
case TUMBLE_END:
return TUMBLE;
case HOP_START:
case HOP_END:
return HOP;
case SESSION_START:
case SESSION_END:
return SESSION;
default:
return null;
}
}
示例14: getParser
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
public Parser getParser(String sql, Properties info)
throws SQLException {
SqlParser parser = SqlParser.create(sql,
SqlParser.configBuilder()
.setQuotedCasing(Casing.UNCHANGED)
.setUnquotedCasing(Casing.UNCHANGED)
.setQuoting(Quoting.DOUBLE_QUOTE)
.setParserFactory(QuarkParserImpl.FACTORY)
.build());
SqlNode sqlNode;
try {
sqlNode = parser.parseStmt();
} catch (SqlParseException e) {
throw new RuntimeException(
"parse failed: " + e.getMessage(), e);
}
if (sqlNode.getKind().equals(SqlKind.OTHER_DDL)) {
return new DDLParser();
} else {
return getSqlQueryParser(info);
}
}
示例15: translateJoinColumn
import org.apache.calcite.sql.SqlKind; //导入依赖的package包/类
void translateJoinColumn(RexCall condition, Map<TblColRef, TblColRef> joinColumns) {
SqlKind kind = condition.getOperator().getKind();
if (kind == SqlKind.AND) {
for (RexNode operand : condition.getOperands()) {
RexCall subCond = (RexCall) operand;
translateJoinColumn(subCond, joinColumns);
}
} else if (kind == SqlKind.EQUALS) {
List<RexNode> operands = condition.getOperands();
RexInputRef op0 = (RexInputRef) operands.get(0);
TblColRef col0 = columnRowType.getColumnByIndex(op0.getIndex());
RexInputRef op1 = (RexInputRef) operands.get(1);
TblColRef col1 = columnRowType.getColumnByIndex(op1.getIndex());
// map left => right
if (op0.getIndex() < columnRowTypeLeftRightCut)
joinColumns.put(col0, col1);
else
joinColumns.put(col1, col0);
}
}