code
stringlengths
25
201k
docstring
stringlengths
19
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
51
path
stringlengths
11
314
url
stringlengths
62
377
license
stringclasses
7 values
public RelOptPredicateList getPredicates(RelSubset r, RelMetadataQuery mq) { if (!Bug.CALCITE_1048_FIXED) { return RelOptPredicateList.EMPTY; } final RexBuilder rexBuilder = r.getCluster().getRexBuilder(); RelOptPredicateList list = null; for (RelNode r2 : r.getRels()) { RelOptPredicateList list2 = mq.getPulledUpPredicates(r2); if (list2 != null) { list = list == null ? list2 : list.union(rexBuilder, list2); } } return Util.first(list, RelOptPredicateList.EMPTY); }
Returns the {@link BuiltInMetadata.Predicates#getPredicates()} statistic. @see RelMetadataQuery#getPulledUpPredicates(RelNode)
getPredicates
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
Apache-2.0
public static double getSelectivity(@Nullable RexNode exp) { if ((exp == null) || exp.isAlwaysTrue()) { return 1d; } return 0.1d; }
Returns a guess for the selectivity of an expression. @param exp expression of interest, or null for none (implying a selectivity of 1.0) @return guessed selectivity
getSelectivity
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static List<RexNode> generateCastExpressions( RexBuilder rexBuilder, RelDataType lhsRowType, RelDataType rhsRowType) { final List<RelDataTypeField> fieldList = rhsRowType.getFieldList(); int n = fieldList.size(); assert n == lhsRowType.getFieldCount() : "field count: lhs [" + lhsRowType + "] rhs [" + rhsRowType + "]"; List<RexNode> rhsExps = new ArrayList<>(); for (RelDataTypeField field : fieldList) { rhsExps.add(rexBuilder.makeInputRef(field.getType(), field.getIndex())); } return generateCastExpressions(rexBuilder, lhsRowType, rhsExps); }
Generates a cast from one row type to another. @param rexBuilder RexBuilder to use for constructing casts @param lhsRowType target row type @param rhsRowType source row type; fields must be 1-to-1 with lhsRowType, in same order @return cast expressions
generateCastExpressions
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static List<RexNode> generateCastExpressions( RexBuilder rexBuilder, RelDataType lhsRowType, List<RexNode> rhsExps) { List<RelDataTypeField> lhsFields = lhsRowType.getFieldList(); List<RexNode> castExps = new ArrayList<>(); for (Pair<RelDataTypeField, RexNode> pair : Pair.zip(lhsFields, rhsExps, true)) { RelDataTypeField lhsField = pair.left; RelDataType lhsType = lhsField.getType(); final RexNode rhsExp = pair.right; RelDataType rhsType = rhsExp.getType(); if (lhsType.equals(rhsType)) { castExps.add(rhsExp); } else { castExps.add(rexBuilder.makeCast(lhsType, rhsExp)); } } return castExps; }
Generates a cast for a row type. @param rexBuilder RexBuilder to use for constructing casts @param lhsRowType target row type @param rhsExps expressions to be cast @return cast expressions
generateCastExpressions
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean isNull(RexNode expr) { switch (expr.getKind()) { case LITERAL: return ((RexLiteral) expr).getValue2() == null; case CAST: return isNull(((RexCall) expr).operands.get(0)); default: return false; } }
Returns whether a node represents the NULL value or a series of nested {@code CAST(NULL AS type)} calls. For example: <code>isNull(CAST(CAST(NULL as INTEGER) AS VARCHAR(1)))</code> returns {@code true}.
isNull
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean isSymbolLiteral(RexNode expr) { switch (expr.getKind()) { case LITERAL: return ((RexLiteral) expr).getTypeName() == SqlTypeName.SYMBOL; case CAST: return isSymbolLiteral(((RexCall) expr).operands.get(0)); default: return false; } }
Returns whether a node represents a {@link SqlTypeName#SYMBOL} literal.
isSymbolLiteral
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean isLiteral(RexNode node, boolean allowCast) { assert node != null; if (node.isA(SqlKind.LITERAL)) { return true; } if (allowCast) { if (node.isA(SqlKind.CAST)) { RexCall call = (RexCall) node; if (isLiteral(call.operands.get(0), false)) { // node is "CAST(literal as type)" return true; } } } return false; }
Returns whether a node represents a literal. <p>Examples: <ul> <li>For <code>CAST(literal AS <i>type</i>)</code>, returns true if <code> allowCast</code> is true, false otherwise. <li>For <code>CAST(CAST(literal AS <i>type</i>) AS <i>type</i>))</code>, returns false. </ul> @param node The node, never null. @param allowCast whether to regard CAST(literal) as a literal @return Whether the node is a literal
isLiteral
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean allLiterals(List<RexNode> expressionOperands) { for (RexNode rexNode : expressionOperands) { if (!isLiteral(rexNode, true)) { return false; } } return true; }
Returns whether every expression in a list is a literal. @param expressionOperands list of expressions to check @return true if every expression from the specified list is literal.
allLiterals
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean isReferenceOrAccess(RexNode node, boolean allowCast) { assert node != null; if (node instanceof RexInputRef || node instanceof RexFieldAccess) { return true; } if (allowCast) { if (node.isA(SqlKind.CAST)) { RexCall call = (RexCall) node; return isReferenceOrAccess(call.operands.get(0), false); } } return false; }
Returns whether a node represents an input reference or field access. @param node The node, never null. @param allowCast whether to regard CAST(x) as true @return Whether the node is a reference or access
isReferenceOrAccess
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean isNullabilityCast(RelDataTypeFactory typeFactory, RexNode node) { switch (node.getKind()) { case CAST: final RexCall call = (RexCall) node; final RexNode arg0 = call.getOperands().get(0); return SqlTypeUtil.equalSansNullability( typeFactory, arg0.getType(), call.getType()); default: break; } return false; }
Returns whether an expression is a cast just for the purposes of nullability, not changing any other aspect of the type.
isNullabilityCast
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode removeNullabilityCast(RelDataTypeFactory typeFactory, RexNode node) { while (isNullabilityCast(typeFactory, node)) { node = ((RexCall) node).operands.get(0); } return node; }
Removes any casts that change nullability but not type. <p>For example, {@code CAST(1 = 0 AS BOOLEAN)} becomes {@code 1 = 0}.
removeNullabilityCast
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode removeCast(RexNode e) { for (; ; ) { switch (e.getKind()) { case CAST: e = ((RexCall) e).operands.get(0); break; default: return e; } } }
Removes any casts. <p>For example, {@code CAST('1' AS INTEGER)} becomes {@code '1'}.
removeCast
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
private static boolean canAssignFrom( RelDataType type1, RelDataType type2, RelDataTypeFactory typeFactory) { final SqlTypeName name1 = type1.getSqlTypeName(); final SqlTypeName name2 = type2.getSqlTypeName(); final RelDataType type1Final = type1; SqlTypeFamily family = requireNonNull( name1.getFamily(), () -> "SqlTypeFamily is null for type " + type1Final + ", SqlTypeName " + name1); if (family == name2.getFamily()) { switch (family) { case NUMERIC: if (SqlTypeUtil.isExactNumeric(type1) && SqlTypeUtil.isExactNumeric(type2)) { int precision1; int scale1; if (name1 == SqlTypeName.DECIMAL) { type1 = typeFactory.decimalOf(type1); precision1 = type1.getPrecision(); scale1 = type1.getScale(); } else { precision1 = typeFactory.getTypeSystem().getMaxPrecision(name1); scale1 = typeFactory.getTypeSystem().getMaxScale(name1); } int precision2; int scale2; if (name2 == SqlTypeName.DECIMAL) { type2 = typeFactory.decimalOf(type2); precision2 = type2.getPrecision(); scale2 = type2.getScale(); } else { precision2 = typeFactory.getTypeSystem().getMaxPrecision(name2); scale2 = typeFactory.getTypeSystem().getMaxScale(name2); } return precision1 >= precision2 && scale1 >= scale2; } else if (SqlTypeUtil.isApproximateNumeric(type1) && SqlTypeUtil.isApproximateNumeric(type2)) { return type1.getPrecision() >= type2.getPrecision() && type1.getScale() >= type2.getScale(); } break; default: // getPrecision() will return: // - number of decimal digits for fractional seconds for datetime types // - length in characters for character types // - length in bytes for binary types // - RelDataType.PRECISION_NOT_SPECIFIED (-1) if not applicable for this type return type1.getPrecision() >= type2.getPrecision(); } } return false; }
Returns whether a value of {@code type2} can be assigned to a variable of {@code type1}. <p>For example: <ul> <li>{@code canAssignFrom(BIGINT, TINYINT)} returns {@code true} <li>{@code canAssignFrom(TINYINT, BIGINT)} returns {@code false} <li>{@code canAssignFrom(BIGINT, VARCHAR)} returns {@code false} </ul>
canAssignFrom
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode expandSearch( RexBuilder rexBuilder, @Nullable RexProgram program, RexNode node) { return expandSearch(rexBuilder, program, node, -1); }
Expands all the calls to {@link SqlStdOperatorTable#SEARCH} in an expression.
expandSearch
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode expandSearch( RexBuilder rexBuilder, @Nullable RexProgram program, RexNode node, int maxComplexity) { return node.accept(searchShuttle(rexBuilder, program, maxComplexity)); }
Expands calls to {@link SqlStdOperatorTable#SEARCH} whose complexity is greater than {@code maxComplexity} in an expression.
expandSearch
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean isConstant(RexNode node) { return node.accept(ConstantFinder.INSTANCE); }
Returns whether node is made up of constants. @param node Node to inspect @return true if node is made up of constants, false otherwise
isConstant
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean requiresDecimalExpansion(RexNode expr, boolean recurse) { if (!(expr instanceof RexCall)) { return false; } RexCall call = (RexCall) expr; boolean localCheck = true; switch (call.getKind()) { case REINTERPRET: case IS_NULL: localCheck = false; break; case CAST: RelDataType lhsType = call.getType(); RelDataType rhsType = call.operands.get(0).getType(); if (rhsType.getSqlTypeName() == SqlTypeName.NULL) { return false; } if (SqlTypeUtil.inCharFamily(lhsType) || SqlTypeUtil.inCharFamily(rhsType)) { localCheck = false; } else if (SqlTypeUtil.isDecimal(lhsType) && (lhsType != rhsType)) { return true; } break; default: localCheck = call.getOperator().requiresDecimalExpansion(); } if (localCheck) { if (SqlTypeUtil.isDecimal(call.getType())) { // NOTE jvs 27-Mar-2007: Depending on the type factory, the // result of a division may be decimal, even though both inputs // are integer. return true; } for (int i = 0; i < call.operands.size(); i++) { if (SqlTypeUtil.isDecimal(call.operands.get(i).getType())) { return true; } } } return recurse && requiresDecimalExpansion(call.operands, true); }
Determines whether a {@link RexCall} requires decimal expansion. It usually requires expansion if it has decimal operands. <p>Exceptions to this rule are: <ul> <li>isNull doesn't require expansion <li>It's okay to cast decimals to and from char types <li>It's okay to cast nulls as decimals <li>Casts require expansion if their return type is decimal <li>Reinterpret casts can handle a decimal operand </ul> @param expr expression possibly in need of expansion @param recurse whether to check nested calls @return whether the expression requires expansion
requiresDecimalExpansion
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean requiresDecimalExpansion(List<RexNode> operands, boolean recurse) { for (RexNode operand : operands) { if (operand instanceof RexCall) { RexCall call = (RexCall) operand; if (requiresDecimalExpansion(call, recurse)) { return true; } } } return false; }
Determines whether any operand of a set requires decimal expansion.
requiresDecimalExpansion
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean containNoCommonExprs(List<RexNode> exprs, Litmus litmus) { final ExpressionNormalizer visitor = new ExpressionNormalizer(false); for (RexNode expr : exprs) { try { expr.accept(visitor); } catch (ExpressionNormalizer.SubExprExistsException e) { Util.swallow(e, null); return litmus.fail(null); } } return litmus.succeed(); }
Returns whether an array of expressions has any common sub-expressions.
containNoCommonExprs
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean containNoForwardRefs( List<RexNode> exprs, RelDataType inputRowType, Litmus litmus) { final ForwardRefFinder visitor = new ForwardRefFinder(inputRowType); for (int i = 0; i < exprs.size(); i++) { RexNode expr = exprs.get(i); visitor.setLimit(i); // field cannot refer to self or later field try { expr.accept(visitor); } catch (ForwardRefFinder.IllegalForwardRefException e) { Util.swallow(e, null); return litmus.fail("illegal forward reference in {}", expr); } } return litmus.succeed(); }
Returns whether an array of expressions contains no forward references. That is, if expression #i contains a {@link RexInputRef} referencing field i or greater. @param exprs Array of expressions @param inputRowType Input row type @param litmus What to do if an error is detected (there is a forward reference) @return Whether there is a forward reference
containNoForwardRefs
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
static boolean containNoNonTrivialAggs(List<RexNode> exprs, Litmus litmus) { for (RexNode expr : exprs) { if (expr instanceof RexCall) { RexCall rexCall = (RexCall) expr; if (rexCall.getOperator() instanceof SqlAggFunction) { for (RexNode operand : rexCall.operands) { if (!(operand instanceof RexLocalRef) && !(operand instanceof RexLiteral)) { return litmus.fail("contains non trivial agg: {}", operand); } } } } } return litmus.succeed(); }
Returns whether an array of exp contains no aggregate function calls whose arguments are not {@link RexInputRef}s. @param exprs Expressions @param litmus Whether to assert if there is such a function call
containNoNonTrivialAggs
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean containComplexExprs(List<RexNode> exprs) { for (RexNode expr : exprs) { if (expr instanceof RexCall) { for (RexNode operand : ((RexCall) expr).operands) { if (!isAtomic(operand)) { return true; } } } } return false; }
Returns whether a list of expressions contains complex expressions, that is, a call whose arguments are not {@link RexVariable} (or a subtype such as {@link RexInputRef}) or {@link RexLiteral}.
containComplexExprs
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean containsTableInputRef(List<RexNode> nodes) { for (RexNode e : nodes) { if (containsTableInputRef(e) != null) { return true; } } return false; }
Returns whether any of the given expression trees contains a {link RexTableInputRef} node. @param nodes a list of RexNode trees @return true if at least one was found, otherwise false
containsTableInputRef
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean isCallTo(RexNode expr, SqlOperator op) { return (expr instanceof RexCall) && (((RexCall) expr).getOperator() == op); }
Returns whether a {@link RexNode node} is a {@link RexCall call} to a given {@link SqlOperator operator}.
isCallTo
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RelDataType createStructType( RelDataTypeFactory typeFactory, final List<RexNode> exprs) { return createStructType(typeFactory, exprs, null, null); }
Creates a record type with anonymous field names. @param typeFactory Type factory @param exprs Expressions @return Record type
createStructType
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static Pair<RexNode, String> makeKey(RexNode expr) { return Pair.of(expr, expr.getType().getFullTypeString()); }
Creates a key for {@link RexNode} which is the same as another key of another RexNode only if the two have both the same type and textual representation. For example, "10" integer and "10" bigint result in different keys.
makeKey
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean containIdentity( List<? extends RexNode> exprs, RelDataType rowType, Litmus litmus) { final List<RelDataTypeField> fields = rowType.getFieldList(); if (exprs.size() < fields.size()) { return litmus.fail("exprs/rowType length mismatch"); } for (int i = 0; i < fields.size(); i++) { if (!(exprs.get(i) instanceof RexInputRef)) { return litmus.fail("expr[{}] is not a RexInputRef", i); } RexInputRef inputRef = (RexInputRef) exprs.get(i); if (inputRef.getIndex() != i) { return litmus.fail("expr[{}] has ordinal {}", i, inputRef.getIndex()); } if (!RelOptUtil.eq( "type1", exprs.get(i).getType(), "type2", fields.get(i).getType(), litmus)) { return litmus.fail(null); } } return litmus.succeed(); }
Returns whether the leading edge of a given array of expressions is wholly {@link RexInputRef} objects with types corresponding to the underlying datatype.
containIdentity
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean isIdentity(List<? extends RexNode> exps, RelDataType inputRowType) { return inputRowType.getFieldCount() == exps.size() && containIdentity(exps, inputRowType, Litmus.IGNORE); }
Returns whether a list of expressions projects the incoming fields.
isIdentity
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode composeConjunction( RexBuilder rexBuilder, Iterable<? extends @Nullable RexNode> nodes) { final RexNode e = composeConjunction(rexBuilder, nodes, false); return requireNonNull(e, "e"); }
As {@link #composeConjunction(RexBuilder, Iterable, boolean)} but never returns null.
composeConjunction
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static @Nullable RexNode composeConjunction( RexBuilder rexBuilder, Iterable<? extends @Nullable RexNode> nodes, boolean nullOnEmpty) { ImmutableList<RexNode> list = flattenAnd(nodes); switch (list.size()) { case 0: return nullOnEmpty ? null : rexBuilder.makeLiteral(true); case 1: return list.get(0); default: if (containsFalse(list)) { return rexBuilder.makeLiteral(false); } return rexBuilder.makeCall(SqlStdOperatorTable.AND, list); } }
Converts a collection of expressions into an AND. If there are zero expressions, returns TRUE. If there is one expression, returns just that expression. If any of the expressions are FALSE, returns FALSE. Removes expressions that always evaluate to TRUE. Returns null only if {@code nullOnEmpty} and expression is TRUE.
composeConjunction
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode composeDisjunction( RexBuilder rexBuilder, Iterable<? extends RexNode> nodes) { final RexNode e = composeDisjunction(rexBuilder, nodes, false); return requireNonNull(e, "e"); }
Converts a collection of expressions into an OR. If there are zero expressions, returns FALSE. If there is one expression, returns just that expression. If any of the expressions are TRUE, returns TRUE. Removes expressions that always evaluate to FALSE. Flattens expressions that are ORs.
composeDisjunction
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static @Nullable RexNode composeDisjunction( RexBuilder rexBuilder, Iterable<? extends RexNode> nodes, boolean nullOnEmpty) { ImmutableList<RexNode> list = flattenOr(nodes); switch (list.size()) { case 0: return nullOnEmpty ? null : rexBuilder.makeLiteral(false); case 1: return list.get(0); default: if (containsTrue(list)) { return rexBuilder.makeLiteral(true); } return rexBuilder.makeCall(SqlStdOperatorTable.OR, list); } }
Converts a collection of expressions into an OR, optionally returning null if the list is empty.
composeDisjunction
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static List<RelCollation> apply( Mappings.TargetMapping mapping, List<RelCollation> collationList) { final List<RelCollation> newCollationList = new ArrayList<>(); for (RelCollation collation : collationList) { final List<RelFieldCollation> newFieldCollationList = new ArrayList<>(); for (RelFieldCollation fieldCollation : collation.getFieldCollations()) { final RelFieldCollation newFieldCollation = apply(mapping, fieldCollation); if (newFieldCollation == null) { // This field is not mapped. Stop here. The leading edge // of the collation is still valid (although it's useless // if it's empty). break; } newFieldCollationList.add(newFieldCollation); } // Truncation to collations to their leading edge creates empty // and duplicate collations. Ignore these. if (!newFieldCollationList.isEmpty()) { final RelCollation newCollation = RelCollations.of(newFieldCollationList); if (!newCollationList.contains(newCollation)) { newCollationList.add(newCollation); } } } // REVIEW: There might be redundant collations in the list. For example, // in {(x), (x, y)}, (x) is redundant because it is a leading edge of // another collation in the list. Could remove redundant collations. return newCollationList; }
Applies a mapping to a collation list. @param mapping Mapping @param collationList Collation list @return collation list with mapping applied to each field
apply
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RelCollation apply(Mappings.TargetMapping mapping, RelCollation collation) { List<RelFieldCollation> fieldCollations = applyFields(mapping, collation.getFieldCollations()); return fieldCollations.equals(collation.getFieldCollations()) ? collation : RelCollations.of(fieldCollations); }
Applies a mapping to a collation. @param mapping Mapping @param collation Collation @return collation with mapping applied
apply
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static @Nullable RelFieldCollation apply( Mappings.TargetMapping mapping, RelFieldCollation fieldCollation) { final int target = mapping.getTargetOpt(fieldCollation.getFieldIndex()); if (target < 0) { return null; } return fieldCollation.withFieldIndex(target); }
Applies a mapping to a field collation. <p>If the field is not mapped, returns null. @param mapping Mapping @param fieldCollation Field collation @return collation with mapping applied
apply
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static List<RelFieldCollation> applyFields( Mappings.TargetMapping mapping, List<RelFieldCollation> fieldCollations) { final List<RelFieldCollation> newFieldCollations = new ArrayList<>(); for (RelFieldCollation fieldCollation : fieldCollations) { RelFieldCollation newFieldCollation = apply(mapping, fieldCollation); if (newFieldCollation == null) { break; } newFieldCollations.add(newFieldCollation); } return newFieldCollations; }
Applies a mapping to a list of field collations. @param mapping Mapping @param fieldCollations Field collations @return collations with mapping applied
applyFields
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static List<RexNode> apply( Mappings.TargetMapping mapping, Iterable<? extends RexNode> nodes) { return RexPermuteInputsShuttle.of(mapping).visitList(nodes); }
Applies a mapping to an iterable over expressions.
apply
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static <T extends RexNode> T[] apply(RexVisitor<T> shuttle, T[] exprs) { T[] newExprs = exprs.clone(); for (int i = 0; i < newExprs.length; i++) { final RexNode expr = newExprs[i]; if (expr != null) { newExprs[i] = expr.accept(shuttle); } } return newExprs; }
Applies a shuttle to an array of expressions. Creates a copy first. @param shuttle Shuttle @param exprs Array of expressions
apply
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static void apply(RexVisitor<Void> visitor, RexNode[] exprs, @Nullable RexNode expr) { for (RexNode e : exprs) { e.accept(visitor); } if (expr != null) { expr.accept(visitor); } }
Applies a visitor to an array of expressions and, if specified, a single expression. @param visitor Visitor @param exprs Array of expressions @param expr Single expression, may be null
apply
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static void apply( RexVisitor<Void> visitor, List<? extends RexNode> exprs, @Nullable RexNode expr) { for (RexNode e : exprs) { e.accept(visitor); } if (expr != null) { expr.accept(visitor); } }
Applies a visitor to a list of expressions and, if specified, a single expression. @param visitor Visitor @param exprs List of expressions @param expr Single expression, may be null
apply
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
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; }
Flattens an expression. <p>Returns the same expression if it is already flat.
flatten
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static List<RexNode> flatten(List<? extends RexNode> exprs, SqlOperator op) { if (isFlat(exprs, op)) { //noinspection unchecked return (List) exprs; } final List<RexNode> list = new ArrayList<>(); flattenRecurse(list, exprs, op); return list; }
Converts a list of operands into a list that is flat with respect to the given operator. The operands are assumed to be flat already.
flatten
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
private static boolean isFlat(List<? extends RexNode> exprs, final SqlOperator op) { return !isAssociative(op) || !exists(exprs, (Predicate1<RexNode>) expr -> isCallTo(expr, op)); }
Returns whether a call to {@code op} with {@code exprs} as arguments would be considered "flat". <p>For example, {@code isFlat([w, AND[x, y], z, AND)} returns false; <p>{@code isFlat([w, x, y, z], AND)} returns true.
isFlat
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean isLosslessCast(RexNode node) { if (!node.isA(SqlKind.CAST)) { return false; } return isLosslessCast(((RexCall) node).getOperands().get(0).getType(), node.getType()); }
Returns whether the input is a 'loss-less' cast, that is, a cast from which the original value of the field can be certainly recovered. <p>For instance, int &rarr; bigint is loss-less (as you can cast back to int without loss of information), but bigint &rarr; int is not loss-less. <p>The implementation of this method does not return false positives. However, it is not complete. @param node input node to verify if it represents a loss-less cast @return true iff the node is a loss-less cast
isLosslessCast
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
@API(since = "1.22", status = API.Status.EXPERIMENTAL) public static boolean isLosslessCast(RelDataType source, RelDataType target) { final SqlTypeName sourceSqlTypeName = source.getSqlTypeName(); final SqlTypeName targetSqlTypeName = target.getSqlTypeName(); // 1) Both INT numeric types if (SqlTypeFamily.INTEGER.getTypeNames().contains(sourceSqlTypeName) && SqlTypeFamily.INTEGER.getTypeNames().contains(targetSqlTypeName)) { return targetSqlTypeName.compareTo(sourceSqlTypeName) >= 0; } // 2) Both CHARACTER types: it depends on the precision (length) if (SqlTypeFamily.CHARACTER.getTypeNames().contains(sourceSqlTypeName) && SqlTypeFamily.CHARACTER.getTypeNames().contains(targetSqlTypeName)) { return targetSqlTypeName.compareTo(sourceSqlTypeName) >= 0 && source.getPrecision() <= target.getPrecision(); } // 3) From NUMERIC family to CHARACTER family: it depends on the precision/scale if (sourceSqlTypeName.getFamily() == SqlTypeFamily.NUMERIC && targetSqlTypeName.getFamily() == SqlTypeFamily.CHARACTER) { int sourceLength = source.getPrecision() + 1; // include sign if (source.getScale() != -1 && source.getScale() != 0) { sourceLength += source.getScale() + 1; // include decimal mark } return target.getPrecision() >= sourceLength; } // Return FALSE by default return false; }
Returns whether the conversion from {@code source} to {@code target} type is a 'loss-less' cast, that is, a cast from which the original value of the field can be certainly recovered. <p>For instance, int &rarr; bigint is loss-less (as you can cast back to int without loss of information), but bigint &rarr; int is not loss-less. <p>The implementation of this method does not return false positives. However, it is not complete. @param source source type @param target target type @return true iff the conversion is a loss-less cast
isLosslessCast
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode toCnf(RexBuilder rexBuilder, RexNode rex) { return new CnfHelper(rexBuilder, -1).toCnf(rex); }
Converts an expression to conjunctive normal form (CNF). <p>The following expression is in CNF: <blockquote> (a OR b) AND (c OR d) </blockquote> <p>The following expression is not in CNF: <blockquote> (a AND b) OR c </blockquote> <p>but can be converted to CNF: <blockquote> (a OR c) AND (b OR c) </blockquote> <p>The following expression is not in CNF: <blockquote> NOT (a OR NOT b) </blockquote> <p>but can be converted to CNF by applying de Morgan's theorem: <blockquote> NOT a AND b </blockquote> <p>Expressions not involving AND, OR or NOT at the top level are in CNF.
toCnf
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode toCnf(RexBuilder rexBuilder, int maxCnfNodeCount, RexNode rex) { return new CnfHelper(rexBuilder, maxCnfNodeCount).toCnf(rex); }
Similar to {@link #toCnf(RexBuilder, RexNode)}; however, it lets you specify a threshold in the number of nodes that can be created out of the conversion. <p>If the number of resulting nodes exceeds that threshold, stops conversion and returns the original expression. <p>If the threshold is negative it is ignored. <p>Leaf nodes in the expression do not count towards the threshold.
toCnf
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode toDnf(RexBuilder rexBuilder, RexNode rex) { return new DnfHelper(rexBuilder).toDnf(rex); }
Converts an expression to disjunctive normal form (DNF). <p>DNF: It is a form of logical formula which is disjunction of conjunctive clauses. <p>All logical formulas can be converted into DNF. <p>The following expression is in DNF: <blockquote> (a AND b) OR (c AND d) </blockquote> <p>The following expression is not in CNF: <blockquote> (a OR b) AND c </blockquote> <p>but can be converted to DNF: <blockquote> (a AND c) OR (b AND c) </blockquote> <p>The following expression is not in CNF: <blockquote> NOT (a OR NOT b) </blockquote> <p>but can be converted to DNF by applying de Morgan's theorem: <blockquote> NOT a AND b </blockquote> <p>Expressions not involving AND, OR or NOT at the top level are in DNF.
toDnf
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
private static boolean isAssociative(SqlOperator op) { return op.getKind() == SqlKind.AND || op.getKind() == SqlKind.OR; }
Returns whether an operator is associative. AND is associative, which means that "(x AND y) and z" is equivalent to "x AND (y AND z)". We might well flatten the tree, and write "AND(x, y, z)".
isAssociative
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static <E> boolean exists(List<? extends E> list, Predicate1<E> predicate) { for (E e : list) { if (predicate.apply(e)) { return true; } } return false; }
Returns whether there is an element in {@code list} for which {@code predicate} is true.
exists
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static <E> boolean all(List<? extends E> list, Predicate1<E> predicate) { for (E e : list) { if (!predicate.apply(e)) { return false; } } return true; }
Returns whether {@code predicate} is true for all elements of {@code list}.
all
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static List<RexNode> fixUp( final RexBuilder rexBuilder, List<RexNode> nodes, final List<RelDataType> fieldTypes) { return new FixNullabilityShuttle(rexBuilder, fieldTypes).apply(nodes); }
Fixes up the type of all {@link RexInputRef}s in an expression to match differences in nullability. <p>Such differences in nullability occur when expressions are moved through outer joins. <p>Throws if there any greater inconsistencies of type.
fixUp
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean removeAll(List<RexNode> targets, RexNode e) { int count = 0; Iterator<RexNode> iterator = targets.iterator(); while (iterator.hasNext()) { RexNode next = iterator.next(); if (next.equals(e)) { ++count; iterator.remove(); } } return count > 0; }
Removes all expressions from a list that are equivalent to a given expression. Returns whether any were removed.
removeAll
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
@Deprecated // use e1.equals(e2) public static boolean eq(RexNode e1, RexNode e2) { return e1 == e2 || e1.toString().equals(e2.toString()); }
Returns whether two {@link RexNode}s are structurally equal. <p>This method considers structure, not semantics. 'x &lt; y' is not equivalent to 'y &gt; x'.
eq
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
@Deprecated // to be removed before 2.0 public static RexNode simplifyPreservingType(RexBuilder rexBuilder, RexNode e) { return new RexSimplify(rexBuilder, RelOptPredicateList.EMPTY, EXECUTOR) .simplifyPreservingType(e); }
Simplifies a boolean expression, always preserving its type and its nullability. <p>This is useful if you are simplifying expressions in a {@link Project}. @deprecated Use {@link RexSimplify#simplifyPreservingType(RexNode)}, which allows you to specify an {@link RexExecutor}.
simplifyPreservingType
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
@Deprecated // to be removed before 2.0 public static RexNode simplify(RexBuilder rexBuilder, RexNode e) { return new RexSimplify(rexBuilder, RelOptPredicateList.EMPTY, EXECUTOR).simplify(e); }
Simplifies a boolean expression, leaving UNKNOWN values as UNKNOWN, and using the default executor. @deprecated Create a {@link RexSimplify}, then call its {@link RexSimplify#simplify(RexNode, RexUnknownAs)} method.
simplify
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
@Deprecated // to be removed before 2.0 public static RexNode simplify(RexBuilder rexBuilder, RexNode e, boolean unknownAsFalse) { return new RexSimplify(rexBuilder, RelOptPredicateList.EMPTY, EXECUTOR) .simplifyUnknownAs(e, RexUnknownAs.falseIf(unknownAsFalse)); }
Simplifies a boolean expression, using the default executor. <p>In particular: <ul> <li>{@code simplify(x = 1 AND y = 2 AND NOT x = 1)} returns {@code y = 2} <li>{@code simplify(x = 1 AND FALSE)} returns {@code FALSE} </ul> <p>If the expression is a predicate in a WHERE clause, UNKNOWN values have the same effect as FALSE. In situations like this, specify {@code unknownAsFalse = true}, so and we can switch from 3-valued logic to simpler 2-valued logic and make more optimizations. @param rexBuilder Rex builder @param e Expression to simplify @param unknownAsFalse Whether to convert UNKNOWN values to FALSE @deprecated Create a {@link RexSimplify}, then call its {@link RexSimplify#simplify(RexNode, RexUnknownAs)} method.
simplify
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode andNot(RexBuilder rexBuilder, RexNode e, RexNode... notTerms) { return andNot(rexBuilder, e, Arrays.asList(notTerms)); }
Creates the expression {@code e1 AND NOT notTerm1 AND NOT notTerm2 ...}.
andNot
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode andNot( final RexBuilder rexBuilder, RexNode e, Iterable<? extends RexNode> notTerms) { // If "e" is of the form "x = literal", remove all "x = otherLiteral" // terms from notTerms. switch (e.getKind()) { case EQUALS: final RexCall call = (RexCall) e; if (call.getOperands().get(1) instanceof RexLiteral) { notTerms = Util.filter( notTerms, e2 -> { switch (e2.getKind()) { case EQUALS: RexCall call2 = (RexCall) e2; if (call2.getOperands() .get(0) .equals(call.getOperands().get(0)) && call2.getOperands().get(1) instanceof RexLiteral && !call.getOperands() .get(1) .equals( call2.getOperands() .get(1))) { return false; } break; default: break; } return true; }); } break; default: break; } return composeConjunction( rexBuilder, Iterables.concat( ImmutableList.of(e), Util.transform(notTerms, e2 -> not(rexBuilder, e2)))); }
Creates the expression {@code e1 AND NOT notTerm1 AND NOT notTerm2 ...}. <p>Examples: <ul> <li>andNot(p) returns "p" <li>andNot(p, n1, n2) returns "p AND NOT n1 AND NOT n2" <li>andNot(x = 10, x = 20, y = 30, x = 30) returns "x = 10 AND NOT (y = 30)" </ul>
andNot
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
@SuppressWarnings("Guava") @Deprecated // to be removed before 2.0 public static com.google.common.base.Function<RexNode, RexNode> notFn( final RexBuilder rexBuilder) { return e -> not(rexBuilder, e); }
Returns a function that applies NOT to its argument. @deprecated Use {@link #not}
notFn
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
static RexNode not(final RexBuilder rexBuilder, RexNode input) { return input.isAlwaysTrue() ? rexBuilder.makeLiteral(false) : input.isAlwaysFalse() ? rexBuilder.makeLiteral(true) : input.getKind() == SqlKind.NOT ? ((RexCall) input).operands.get(0) : rexBuilder.makeCall(SqlStdOperatorTable.NOT, input); }
Applies NOT to an expression. <p>Unlike {@link #not}, may strengthen the type from {@code BOOLEAN} to {@code BOOLEAN NOT NULL}.
not
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean containsCorrelation(RexNode condition) { try { condition.accept(CorrelationFinder.INSTANCE); return false; } catch (Util.FoundOne e) { return true; } }
Returns whether an expression contains a {@link RexCorrelVariable}.
containsCorrelation
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode swapTableReferences( final RexBuilder rexBuilder, final RexNode node, final Map<RelTableRef, RelTableRef> tableMapping) { return swapTableColumnReferences(rexBuilder, node, tableMapping, null); }
Given an expression, it will swap the table references contained in its {@link RexTableInputRef} using the contents in the map.
swapTableReferences
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static RexNode swapColumnReferences( final RexBuilder rexBuilder, final RexNode node, final Map<RexTableInputRef, Set<RexTableInputRef>> ec) { return swapTableColumnReferences(rexBuilder, node, null, ec); }
Given an expression, it will swap its column references {@link RexTableInputRef} using the contents in the map (in particular, the first element of the set in the map value).
swapColumnReferences
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static ImmutableBitSet getNonConstColumns(List<RexNode> expressions) { ImmutableBitSet cols = ImmutableBitSet.range(0, expressions.size()); return getNonConstColumns(cols, expressions); }
Given some expressions, gets the indices of the non-constant ones.
getNonConstColumns
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static ImmutableBitSet getNonConstColumns( ImmutableBitSet columns, List<RexNode> expressions) { ImmutableBitSet.Builder nonConstCols = ImmutableBitSet.builder(); for (int col : columns) { if (!isLiteral(expressions.get(col), true)) { nonConstCols.set(col); } } return nonConstCols.build(); }
Given some expressions and columns, gets the indices of the non-constant ones.
getNonConstColumns
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static List<String> strings(List<RexNode> list) { return Util.transform(list, Object::toString); }
Transforms a list of expressions to the list of digests.
strings
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
@Override public RexNode visitInputRef(RexInputRef input) { return new RexInputRef(input.getIndex() + offset, input.getType()); }
Shuttle that adds {@code offset} to each {@link RexInputRef} in an expression.
visitInputRef
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
@Override public RexNode visitInputRef(RexInputRef ref) { final RelDataType rightType = typeList.get(ref.getIndex()); final RelDataType refType = ref.getType(); if (refType.equals(rightType)) { return ref; } final RelDataType refType2 = rexBuilder .getTypeFactory() .createTypeWithNullability(refType, rightType.isNullable()); if (refType2.equals(rightType)) { return new RexInputRef(ref.getIndex(), refType2); } throw new AssertionError("mismatched type " + ref + " " + rightType); }
Shuttle that fixes up an expression to match changes in nullability of input fields.
visitInputRef
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean containsSubQuery(Project project) { for (RexNode node : project.getProjects()) { try { node.accept(INSTANCE); } catch (Util.FoundOne e) { return true; } } return false; }
Returns whether a {@link Project} contains a sub-query.
containsSubQuery
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public static boolean containsSubQuery(Filter filter) { try { filter.getCondition().accept(INSTANCE); return false; } catch (Util.FoundOne e) { return true; } }
Returns whether a {@link Filter} contains a sub-query.
containsSubQuery
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
@Override public RexNode visitCall(RexCall call) { RexUnknownAs unknownAs = this.unknownAs; switch (unknownAs) { case FALSE: switch (call.getKind()) { case AND: case CASE: // Default value is used for top operator unknownAs = unknownAsMap.getOrDefault(call, RexUnknownAs.FALSE); break; default: unknownAs = RexUnknownAs.FALSE; } for (RexNode operand : call.operands) { this.unknownAsMap.put(operand, unknownAs); } break; default: break; } RexNode node = super.visitCall(call); RexNode simplifiedNode = simplify.simplify(node, unknownAs); if (node == simplifiedNode) { return node; } if (simplifiedNode.getType().equals(call.getType())) { return simplifiedNode; } return simplify.rexBuilder.makeCast(call.getType(), simplifiedNode, matchNullability); }
Deep expressions simplifier. <p>This class is broken because it does not change the value of {@link RexUnknownAs} as it recurses into an expression. Do not use.
visitCall
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public boolean inProject(Project project) { return anyContain(project.getProjects()); }
Returns whether a {@link Project} contains the kind of expression we seek.
inProject
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public boolean inFilter(Filter filter) { return contains(filter.getCondition()); }
Returns whether a {@link Filter} contains the kind of expression we seek.
inFilter
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public boolean inJoin(Join join) { return contains(join.getCondition()); }
Returns whether a {@link Join} contains kind of expression we seek.
inJoin
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public boolean contains(RexNode node) { try { node.accept(RexFinder.this); return false; } catch (Util.FoundOne e) { return true; } }
Returns whether the given expression contains what this RexFinder seeks.
contains
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
public boolean anyContain(Iterable<? extends RexNode> nodes) { try { for (RexNode node : nodes) { node.accept(RexFinder.this); } return false; } catch (Util.FoundOne e) { return true; } }
Returns whether any of the given expressions contain what this RexFinder seeks.
anyContain
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/rex/RexUtil.java
Apache-2.0
@Deprecated // to be removed before 2.0 public @Nullable List<RelDataType> getParamTypes() { return null; }
Use {@link SqlOperandMetadata#paramTypes(RelDataTypeFactory)} on the result of {@link #getOperandTypeChecker()}.
getParamTypes
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlFunction.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlFunction.java
Apache-2.0
public SqlGroupedWindowFunction auxiliary(SqlKind kind) { return auxiliary(kind.name(), kind); }
Creates an auxiliary function from this grouped window function. @param kind Kind; also determines function name
auxiliary
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlGroupedWindowFunction.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlGroupedWindowFunction.java
Apache-2.0
public SqlGroupedWindowFunction auxiliary(String name, SqlKind kind) { switch (kind) { case TUMBLE_START: case TUMBLE_END: case HOP_START: case HOP_END: case SESSION_START: case SESSION_END: return new SqlGroupedWindowFunction( name, kind, this, windowStartEndInf, null, getOperandTypeChecker(), SqlFunctionCategory.SYSTEM); default: return new SqlGroupedWindowFunction( name, kind, this, ReturnTypes.ARG0, null, getOperandTypeChecker(), SqlFunctionCategory.SYSTEM); } }
Creates an auxiliary function from this grouped window function. @param name Function name @param kind Kind
auxiliary
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlGroupedWindowFunction.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlGroupedWindowFunction.java
Apache-2.0
public RelDataType inferReturnType(SqlOperatorBinding opBinding) { return explicit.inferReturnType(opBinding); }
ReturnTypeInference that returns TIMESTAMP(3) as the type of window start and window end. <p>We use the first operand of window function to decide the return type which can avoid many necessary `CAST(w$end) AS EXPR$1` expressions that will be produced we directly use `ReturnTypes.explicit(SqlTypeName.TIMESTAMP, 3)`.
inferReturnType
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlGroupedWindowFunction.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlGroupedWindowFunction.java
Apache-2.0
@Override public RelDataType deriveType( SqlValidator validator, SqlValidatorScope scope, SqlCall call) { return model.getOutputRowType(validator.getTypeFactory()); }
A custom SqlOperator to handle model identifier. <p>It is used to derive the type of the model based on the identifier.
deriveType
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlModelCall.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlModelCall.java
Apache-2.0
public static int indexOfDeep(List<? extends SqlNode> list, SqlNode e, Litmus litmus) { for (int i = 0; i < list.size(); i++) { if (e.equalsDeep(list.get(i), litmus)) { return i; } } return -1; }
Finds the index of an expression in a list, comparing using {@link SqlNode#equalsDeep(SqlNode, Litmus)}.
indexOfDeep
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static boolean isNullLiteral(@Nullable SqlNode node, boolean allowCast) { if (node instanceof SqlLiteral) { SqlLiteral literal = (SqlLiteral) node; if (literal.getTypeName() == SqlTypeName.NULL) { assert null == literal.getValue(); return true; } else { // We don't regard UNKNOWN -- SqlLiteral(null,Boolean) -- as // NULL. return false; } } if (allowCast && node != null) { if (node.getKind() == SqlKind.CAST) { SqlCall call = (SqlCall) node; if (isNullLiteral(call.operand(0), false)) { // node is "CAST(NULL as type)" return true; } } } return false; }
Returns whether a node represents the NULL value. <p>Examples: <ul> <li>For {@link SqlLiteral} Unknown, returns false. <li>For <code>CAST(NULL AS <i>type</i>)</code>, returns true if <code> allowCast</code> is true, false otherwise. <li>For <code>CAST(CAST(NULL AS <i>type</i>) AS <i>type</i>))</code>, returns false. </ul>
isNullLiteral
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static boolean isNull(SqlNode node) { return isNullLiteral(node, false) || node.getKind() == SqlKind.CAST && isNull(((SqlCall) node).operand(0)); }
Returns whether a node represents the NULL value or a series of nested <code> CAST(NULL AS type)</code> calls. For example: <code> isNull(CAST(CAST(NULL as INTEGER) AS VARCHAR(1)))</code> returns {@code true}.
isNull
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static boolean isLiteral(SqlNode node, boolean allowCast) { assert node != null; if (node instanceof SqlLiteral) { return true; } if (!allowCast) { return false; } switch (node.getKind()) { case CAST: // "CAST(e AS type)" is literal if "e" is literal return isLiteral(((SqlCall) node).operand(0), true); case MAP_VALUE_CONSTRUCTOR: case ARRAY_VALUE_CONSTRUCTOR: return ((SqlCall) node).getOperandList().stream().allMatch(o -> isLiteral(o, true)); case DEFAULT: return true; // DEFAULT is always NULL default: return false; } }
Returns whether a node is a literal. <p>Examples: <ul> <li>For <code>CAST(literal AS <i>type</i>)</code>, returns true if <code> allowCast</code> is true, false otherwise. <li>For <code>CAST(CAST(literal AS <i>type</i>) AS <i>type</i>))</code>, returns false. </ul> @param node The node, never null. @param allowCast whether to regard CAST(literal) as a literal @return Whether the node is a literal
isLiteral
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static boolean isLiteral(SqlNode node) { return isLiteral(node, false); }
Returns whether a node is a literal. <p>Many constructs which require literals also accept <code>CAST(NULL AS <i>type</i>)</code>. This method does not accept casts, so you should call {@link #isNullLiteral} first. @param node The node, never null. @return Whether the node is a literal
isLiteral
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static void unparseFunctionSyntax( SqlOperator operator, SqlWriter writer, SqlCall call, boolean ordered) { if (operator instanceof SqlFunction) { SqlFunction function = (SqlFunction) operator; if (function.getFunctionType().isSpecific()) { writer.keyword("SPECIFIC"); } SqlIdentifier id = function.getSqlIdentifier(); if (id == null) { writer.keyword(operator.getName()); } else { unparseSqlIdentifierSyntax(writer, id, true); } } else { writer.print(operator.getName()); } if (call.operandCount() == 0) { switch (call.getOperator().getSyntax()) { case FUNCTION_ID: // For example, the "LOCALTIME" function appears as "LOCALTIME" // when it has 0 args, not "LOCALTIME()". return; case FUNCTION_STAR: // E.g. "COUNT(*)" case FUNCTION: // E.g. "RANK()" case ORDERED_FUNCTION: // E.g. "STRING_AGG(x)" // fall through - dealt with below break; default: break; } } final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); final SqlLiteral quantifier = call.getFunctionQuantifier(); if (quantifier != null) { quantifier.unparse(writer, 0, 0); } if (call.operandCount() == 0) { switch (call.getOperator().getSyntax()) { case FUNCTION_STAR: writer.sep("*"); break; default: break; } } for (SqlNode operand : call.getOperandList()) { if (ordered && operand instanceof SqlNodeList) { writer.sep("ORDER BY"); } else if (ordered && operand.getKind() == SqlKind.SEPARATOR) { writer.sep("SEPARATOR"); ((SqlCall) operand).operand(0).unparse(writer, 0, 0); continue; } else { writer.sep(","); } operand.unparse(writer, 0, 0); } writer.endList(frame); }
Unparses a call to an operator that has function syntax. @param operator The operator @param writer Writer @param call List of 0 or more operands @param ordered Whether argument list may end with ORDER BY
unparseFunctionSyntax
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static SqlLiteral concatenateLiterals(List<SqlLiteral> lits) { if (lits.size() == 1) { return lits.get(0); // nothing to do } return ((SqlAbstractStringLiteral) lits.get(0)).concat1(lits); }
Concatenates string literals. <p>This method takes an array of arguments, since pairwise concatenation means too much string copying. @param lits an array of {@link SqlLiteral}, not empty, all of the same class @return a new {@link SqlLiteral}, of that same class, whose value is the string concatenation of the values of the literals @throws ClassCastException if the lits are not homogeneous. @throws ArrayIndexOutOfBoundsException if lits is an empty array.
concatenateLiterals
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static Iterator<SqlOperator> lookupSubjectRoutines( SqlOperatorTable opTab, RelDataTypeFactory typeFactory, SqlIdentifier funcName, List<RelDataType> argTypes, @Nullable List<String> argNames, SqlSyntax sqlSyntax, SqlKind sqlKind, @Nullable SqlFunctionCategory category, SqlNameMatcher nameMatcher, boolean coerce) { // start with all routines matching by name Iterator<SqlOperator> routines = lookupSubjectRoutinesByName(opTab, funcName, sqlSyntax, category, nameMatcher); // first pass: eliminate routines which don't accept the given // number of arguments routines = filterRoutinesByParameterCount(routines, argTypes); // NOTE: according to SQL99, procedures are NOT overloaded on type, // only on number of arguments. if (category == SqlFunctionCategory.USER_DEFINED_PROCEDURE) { return routines; } // second pass: eliminate routines which don't accept the given // argument types and parameter names if specified routines = filterRoutinesByParameterTypeAndName( typeFactory, sqlSyntax, routines, argTypes, argNames, coerce); // see if we can stop now; this is necessary for the case // of builtin functions where we don't have param type info, // or UDF whose operands can make type coercion. final List<SqlOperator> list = Lists.newArrayList(routines); routines = list.iterator(); if (list.size() < 2 || coerce) { return routines; } // third pass: for each parameter from left to right, eliminate // all routines except those with the best precedence match for // the given arguments routines = filterRoutinesByTypePrecedence( sqlSyntax, typeFactory, routines, argTypes, argNames); // fourth pass: eliminate routines which do not have the same // SqlKind as requested return filterOperatorRoutinesByKind(routines, sqlKind); }
Looks up all subject routines matching the given name and argument types. @param opTab operator table to search @param typeFactory Type factory @param funcName name of function being invoked @param argTypes argument types @param argNames argument names, or null if call by position @param sqlSyntax the SqlSyntax of the SqlOperator being looked up @param sqlKind the SqlKind of the SqlOperator being looked up @param category Category of routine to look up @param nameMatcher Whether to look up the function case-sensitively @param coerce Whether to allow type coercion when do filter routine by parameter types @return list of matching routines @see Glossary#SQL99 SQL:1999 Part 2 Section 10.4
lookupSubjectRoutines
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
private static Iterator<SqlOperator> filterRoutinesByParameterTypeAndName( RelDataTypeFactory typeFactory, SqlSyntax syntax, final Iterator<SqlOperator> routines, final List<RelDataType> argTypes, final @Nullable List<String> argNames, final boolean coerce) { if (syntax != SqlSyntax.FUNCTION) { return routines; } //noinspection unchecked return (Iterator) Iterators.filter( Iterators.filter(routines, SqlFunction.class), function -> { SqlOperandTypeChecker operandTypeChecker = Objects.requireNonNull(function, "function") .getOperandTypeChecker(); if (operandTypeChecker == null || !operandTypeChecker.isFixedParameters()) { // no parameter information for builtins; keep for now, // the type coerce will not work here. return true; } final SqlOperandMetadata operandMetadata = (SqlOperandMetadata) operandTypeChecker; @SuppressWarnings("assignment.type.incompatible") final List<@Nullable RelDataType> paramTypes = operandMetadata.paramTypes(typeFactory); final List<@Nullable RelDataType> permutedArgTypes; if (argNames != null) { final List<String> paramNames = operandMetadata.paramNames(); permutedArgTypes = permuteArgTypes(paramNames, argNames, argTypes); if (permutedArgTypes == null) { return false; } } else { permutedArgTypes = Lists.newArrayList(argTypes); while (permutedArgTypes.size() < argTypes.size()) { paramTypes.add(null); } } for (Pair<@Nullable RelDataType, @Nullable RelDataType> p : Pair.zip(paramTypes, permutedArgTypes)) { final RelDataType argType = p.right; final RelDataType paramType = p.left; if (argType != null && paramType != null && !SqlTypeUtil.canCastFrom(paramType, argType, coerce)) { return false; } } return true; }); }
Filters an iterator of routines, keeping only those that have the required argument types and names. @see Glossary#SQL99 SQL:1999 Part 2 Section 10.4 Syntax Rule 6.b.iii.2.B
filterRoutinesByParameterTypeAndName
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
private static @Nullable List<@Nullable RelDataType> permuteArgTypes( List<String> paramNames, List<String> argNames, List<RelDataType> argTypes) { // Arguments passed by name. Make sure that the function has // parameters of all of these names. Map<Integer, Integer> map = new HashMap<>(); for (Ord<String> argName : Ord.zip(argNames)) { int i = paramNames.indexOf(argName.e); if (i < 0) { return null; } map.put(i, argName.i); } return Functions.<@Nullable RelDataType>generate( paramNames.size(), index -> { Integer argIndex = map.get(index); return argIndex != null ? argTypes.get(argIndex) : null; }); }
Permutes argument types to correspond to the order of parameter names.
permuteArgTypes
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static boolean isGeneratedAlias(String alias) { assert alias != null; return alias.toUpperCase(Locale.ROOT).startsWith(GENERATED_EXPR_ALIAS_PREFIX); }
Whether the alias is generated by calcite. @param alias not null @return true if alias is generated by calcite, otherwise false
isGeneratedAlias
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static String getOperatorSignature(SqlOperator op, List<?> typeList) { return getAliasedSignature(op, op.getName(), typeList); }
Constructs an operator signature from a type list. @param op operator @param typeList list of types to use for operands. Types may be represented as {@link String}, {@link SqlTypeFamily}, or any object with a valid {@link Object#toString()} method. @return constructed signature
getOperatorSignature
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static String getAliasedSignature(SqlOperator op, String opName, List<?> typeList) { StringBuilder ret = new StringBuilder(); String template = op.getSignatureTemplate(typeList.size()); if (null == template) { ret.append("'"); ret.append(opName); ret.append("("); for (int i = 0; i < typeList.size(); i++) { if (i > 0) { ret.append(", "); } final String t = String.valueOf(typeList.get(i)).toUpperCase(Locale.ROOT); ret.append("<").append(t).append(">"); } ret.append(")'"); } else { Object[] values = new Object[typeList.size() + 1]; values[0] = opName; ret.append("'"); for (int i = 0; i < typeList.size(); i++) { final String t = String.valueOf(typeList.get(i)).toUpperCase(Locale.ROOT); values[i + 1] = "<" + t + ">"; } ret.append(new MessageFormat(template, Locale.ROOT).format(values)); ret.append("'"); assert (typeList.size() + 1) == values.length; } return ret.toString(); }
Constructs an operator signature from a type list, substituting an alias for the operator name. @param op operator @param opName name to use for operator @param typeList list of {@link SqlTypeName} or {@link String} to use for operands @return constructed signature
getAliasedSignature
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static boolean isCallTo(SqlNode node, SqlOperator operator) { return (node instanceof SqlCall) && (((SqlCall) node).getOperator() == operator); }
Returns whether a {@link SqlNode node} is a {@link SqlCall call} to a given {@link SqlOperator operator}.
isCallTo
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static @Nullable String translateCharacterSetName(String name) { switch (name) { case "BIG5": return "Big5"; case "LATIN1": return "ISO-8859-1"; case "UTF8": return "UTF-8"; case "UTF16": case "UTF-16": return ConversionUtil.NATIVE_UTF16_CHARSET_NAME; case "GB2312": case "GBK": case "UTF-16BE": case "UTF-16LE": case "ISO-8859-1": case "UTF-8": return name; default: return null; } }
Translates a character set name from a SQL-level name into a Java-level name. @param name SQL-level name @return Java-level name, or null if SQL-level name is unknown
translateCharacterSetName
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static Charset getCharset(String charsetName) { assert charsetName != null; charsetName = charsetName.toUpperCase(Locale.ROOT); String javaCharsetName = translateCharacterSetName(charsetName); if (javaCharsetName == null) { throw new UnsupportedCharsetException(charsetName); } return Charset.forName(javaCharsetName); }
Returns the Java-level {@link Charset} based on given SQL-level name. @param charsetName Sql charset name, must not be null. @return charset, or default charset if charsetName is null. @throws UnsupportedCharsetException If no support for the named charset is available in this instance of the Java virtual machine
getCharset
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
@SuppressWarnings("BetaApi") public static void validateCharset(ByteString value, Charset charset) { if (charset == StandardCharsets.UTF_8) { final byte[] bytes = value.getBytes(); if (!Utf8.isWellFormed(bytes)) { // CHECKSTYLE: IGNORE 1 final String string = new String(bytes, charset); throw RESOURCE.charsetEncoding(string, charset.name()).ex(); } } }
Validate if value can be decoded by given charset. @param value nls string in byte array @param charset charset @throws RuntimeException If the given value cannot be represented in the given charset
validateCharset
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0
public static @PolyNull SqlNode stripAs(@PolyNull SqlNode node) { if (node != null && node.getKind() == SqlKind.AS) { return ((SqlCall) node).operand(0); } return node; }
If a node is "AS", returns the underlying expression; otherwise returns the node. Returns null if and only if the node is null.
stripAs
java
apache/flink
flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/SqlUtil.java
Apache-2.0