use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project drill by apache.
the class DrillOperatorTable method populateFromTypeInference.
private void populateFromTypeInference(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList) {
final List<SqlOperator> calciteOperatorList = Lists.newArrayList();
inner.lookupOperatorOverloads(opName, category, syntax, calciteOperatorList);
if (!calciteOperatorList.isEmpty()) {
for (SqlOperator calciteOperator : calciteOperatorList) {
if (calciteToWrapper.containsKey(calciteOperator)) {
operatorList.add(calciteToWrapper.get(calciteOperator));
} else {
operatorList.add(calciteOperator);
}
}
} else {
// if no function is found, check in Drill UDFs
if (operatorList.isEmpty() && (syntax == SqlSyntax.FUNCTION || syntax == SqlSyntax.FUNCTION_ID) && opName.isSimple()) {
List<SqlOperator> drillOps = drillOperatorsWithInferenceMap.get(opName.getSimple().toLowerCase());
if (drillOps != null && !drillOps.isEmpty()) {
operatorList.addAll(drillOps);
}
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.
the class RelJson method toOp.
private SqlOperator toOp(String op, Map<String, Object> map) {
// TODO: build a map, for more efficient lookup
// TODO: look up based on SqlKind
final List<SqlOperator> operatorList = SqlStdOperatorTable.instance().getOperatorList();
for (SqlOperator operator : operatorList) {
if (operator.getName().equals(op)) {
return operator;
}
}
String class_ = (String) map.get("class");
if (class_ != null) {
return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_);
}
return null;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.
the class RexUtil method flatten.
/**
* Flattens an expression.
*
* <p>Returns the same expression if it is already flat.
*/
public static RexNode flatten(RexBuilder rexBuilder, RexNode node) {
if (node instanceof RexCall) {
RexCall call = (RexCall) node;
final SqlOperator op = call.getOperator();
final List<RexNode> flattenedOperands = flatten(call.getOperands(), op);
if (!isFlat(call.getOperands(), op)) {
return rexBuilder.makeCall(call.getType(), op, flattenedOperands);
}
}
return node;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.
the class SqlParserUtil method toTreeEx.
/**
* Converts a list of {expression, operator, expression, ...} into a tree,
* taking operator precedence and associativity into account.
*
* @param list List of operands and operators. This list is modified as
* expressions are reduced.
* @param start Position of first operand in the list. Anything to the
* left of this (besides the immediately preceding operand)
* is ignored. Generally use value 1.
* @param minPrec Minimum precedence to consider. If the method encounters
* an operator of lower precedence, it doesn't reduce any
* further.
* @param stopperKind If not {@link SqlKind#OTHER}, stop reading the list if
* we encounter a token of this kind.
* @return the root node of the tree which the list condenses into
*/
public static SqlNode toTreeEx(SqlSpecialOperator.TokenSequence list, int start, final int minPrec, final SqlKind stopperKind) {
final Predicate<PrecedenceClimbingParser.Token> predicate = new PredicateImpl<PrecedenceClimbingParser.Token>() {
public boolean test(PrecedenceClimbingParser.Token t) {
if (t instanceof PrecedenceClimbingParser.Op) {
final SqlOperator op = ((ToTreeListItem) t.o).op;
return stopperKind != SqlKind.OTHER && op.kind == stopperKind || minPrec > 0 && op.getLeftPrec() < minPrec;
} else {
return false;
}
}
};
PrecedenceClimbingParser parser = list.parser(start, predicate);
final int beforeSize = parser.all().size();
parser.partialParse();
final int afterSize = parser.all().size();
final SqlNode node = convert(parser.all().get(0));
list.replaceSublist(start, start + beforeSize - afterSize + 1, node);
return node;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.
the class SqlLikeOperator method reduceExpr.
public ReduceResult reduceExpr(final int opOrdinal, TokenSequence list) {
// Example:
// a LIKE b || c ESCAPE d || e AND f
// | | | | | |
// exp0 exp1 exp2
SqlNode exp0 = list.node(opOrdinal - 1);
SqlOperator op = list.op(opOrdinal);
assert op instanceof SqlLikeOperator;
SqlNode exp1 = SqlParserUtil.toTreeEx(list, opOrdinal + 1, getRightPrec(), SqlKind.ESCAPE);
SqlNode exp2 = null;
if ((opOrdinal + 2) < list.size()) {
if (list.isOp(opOrdinal + 2)) {
final SqlOperator op2 = list.op(opOrdinal + 2);
if (op2.getKind() == SqlKind.ESCAPE) {
exp2 = SqlParserUtil.toTreeEx(list, opOrdinal + 3, getRightPrec(), SqlKind.ESCAPE);
}
}
}
final SqlNode[] operands;
int end;
if (exp2 != null) {
operands = new SqlNode[] { exp0, exp1, exp2 };
end = opOrdinal + 4;
} else {
operands = new SqlNode[] { exp0, exp1 };
end = opOrdinal + 2;
}
SqlCall call = createCall(SqlParserPos.ZERO, operands);
return new ReduceResult(opOrdinal - 1, end, call);
}
Aggregations