Java Code Examples for org.apache.calcite.util.Util#discard()

The following examples show how to use org.apache.calcite.util.Util#discard() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
private SqlNode navigationInMeasure(SqlNode node, boolean allRows) {
	final Set<String> prefix = node.accept(new PatternValidator(true));
	Util.discard(prefix);
	final List<SqlNode> ops = ((SqlCall) node).getOperandList();

	final SqlOperator defaultOp =
		allRows ? SqlStdOperatorTable.RUNNING : SqlStdOperatorTable.FINAL;
	final SqlNode op0 = ops.get(0);
	if (!isRunningOrFinal(op0.getKind())
		|| !allRows && op0.getKind() == SqlKind.RUNNING) {
		SqlNode newNode = defaultOp.createCall(SqlParserPos.ZERO, op0);
		node = SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, newNode, ops.get(1));
	}

	node = new NavigationExpander().go(node);
	return node;
}
 
Example 2
Source File: GeoFunctions.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static Geom buffer(Geom geom, double bufferSize,
    int quadSegCount, CapStyle endCapStyle, JoinStyle joinStyle,
    float mitreLimit) {
  Util.discard(endCapStyle + ":" + joinStyle + ":" + mitreLimit
      + ":" + quadSegCount);
  throw todo();
}
 
Example 3
Source File: EnumerableProject.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Deprecated // to be removed before 2.0
public EnumerableProject(RelOptCluster cluster, RelTraitSet traitSet,
    RelNode input, List<? extends RexNode> projects, RelDataType rowType,
    int flags) {
  this(cluster, traitSet, input, projects, rowType);
  Util.discard(flags);
}
 
Example 4
Source File: FlinkDDLDataTypeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
public void checkFails(
	String sql,
	String expectedMsgPattern) {
	SqlParserUtil.StringAndPos sap = SqlParserUtil.findPos(sql);
	Throwable thrown = null;
	try {
		final SqlNode sqlNode;
		sqlNode = factory.createParser(sap.sql).parseStmt();
		Util.discard(sqlNode);
	} catch (Throwable ex) {
		thrown = ex;
	}

	checkEx(expectedMsgPattern, sap, thrown);
}
 
Example 5
Source File: LiteralOperandTypeChecker.java    From calcite with Apache License 2.0 5 votes vote down vote up
public boolean checkSingleOperandType(
    SqlCallBinding callBinding,
    SqlNode node,
    int iFormalOperand,
    boolean throwOnFailure) {
  Util.discard(iFormalOperand);

  if (SqlUtil.isNullLiteral(node, true)) {
    if (allowNull) {
      return true;
    }
    if (throwOnFailure) {
      throw callBinding.newError(
          RESOURCE.argumentMustNotBeNull(
              callBinding.getOperator().getName()));
    }
    return false;
  }
  if (!SqlUtil.isLiteral(node) && !SqlUtil.isLiteralChain(node)) {
    if (throwOnFailure) {
      throw callBinding.newError(
          RESOURCE.argumentMustBeLiteral(
              callBinding.getOperator().getName()));
    }
    return false;
  }

  return true;
}
 
Example 6
Source File: DiffRepository.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Flushes the reference document to the file system.
 */
private void flushDoc() {
	try {
		boolean b = logFile.getParentFile().mkdirs();
		Util.discard(b);
		try (Writer w = Util.printWriter(logFile)) {
			write(doc, w, indent);
		}
	} catch (IOException e) {
		throw new RuntimeException("error while writing test reference log '"
			+ logFile + "'", e);
	}
}
 
Example 7
Source File: RelMdMinRowCount.java    From Bats with Apache License 2.0 5 votes vote down vote up
public Double getMinRowCount(RelSubset rel, RelMetadataQuery mq) {
  // FIXME This is a short-term fix for [CALCITE-1018]. A complete
  // solution will come with [CALCITE-1048].
  Util.discard(Bug.CALCITE_1048_FIXED);
  for (RelNode node : rel.getRels()) {
    if (node instanceof Sort) {
      Sort sort = (Sort) node;
      if (sort.fetch != null) {
        return (double) RexLiteral.intValue(sort.fetch);
      }
    }
  }

  return 0D;
}
 
Example 8
Source File: FlinkDDLDataTypeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
public void checkFails(
	String sql,
	String expectedMsgPattern) {
	SqlParserUtil.StringAndPos sap = SqlParserUtil.findPos(sql);
	Throwable thrown = null;
	try {
		final SqlNode sqlNode;
		sqlNode = getSqlParser(sap.sql).parseStmt();
		Util.discard(sqlNode);
	} catch (Throwable ex) {
		thrown = ex;
	}

	checkEx(expectedMsgPattern, sap, thrown);
}
 
Example 9
Source File: RelOptUtilTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the rules for how we name rules.
 */
@Test void testRuleGuessDescription() {
  assertEquals("Bar", RelOptRule.guessDescription("com.foo.Bar"));
  assertEquals("Baz", RelOptRule.guessDescription("com.flatten.Bar$Baz"));

  // yields "1" (which as an integer is an invalid
  try {
    Util.discard(RelOptRule.guessDescription("com.foo.Bar$1"));
    fail("expected exception");
  } catch (RuntimeException e) {
    assertEquals("Derived description of rule class com.foo.Bar$1 is an "
            + "integer, not valid. Supply a description manually.",
        e.getMessage());
  }
}
 
Example 10
Source File: PigRelFactories.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public RelNode createAggregate(RelNode input,
    List<RelHint> hints,
    ImmutableBitSet groupSet, ImmutableList<ImmutableBitSet> groupSets,
    List<AggregateCall> aggCalls) {
  Util.discard(hints);
  return new PigAggregate(input.getCluster(), input.getTraitSet(), input,
      groupSet, groupSets, aggCalls);
}
 
Example 11
Source File: StreamRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public void onMatch(RelOptRuleCall call) {
  final Delta delta = call.rel(0);
  Util.discard(delta);
  final Sort sort = call.rel(1);
  final LogicalDelta newDelta =
      LogicalDelta.create(sort.getInput());
  final LogicalSort newSort =
      LogicalSort.create(newDelta, sort.collation, sort.offset, sort.fetch);
  call.transformTo(newSort);
}
 
Example 12
Source File: LiteralOperandTypeChecker.java    From Bats with Apache License 2.0 5 votes vote down vote up
public boolean checkSingleOperandType(
    SqlCallBinding callBinding,
    SqlNode node,
    int iFormalOperand,
    boolean throwOnFailure) {
  Util.discard(iFormalOperand);

  if (SqlUtil.isNullLiteral(node, true)) {
    if (allowNull) {
      return true;
    }
    if (throwOnFailure) {
      throw callBinding.newError(
          RESOURCE.argumentMustNotBeNull(
              callBinding.getOperator().getName()));
    }
    return false;
  }
  if (!SqlUtil.isLiteral(node) && !SqlUtil.isLiteralChain(node)) {
    if (throwOnFailure) {
      throw callBinding.newError(
          RESOURCE.argumentMustBeLiteral(
              callBinding.getOperator().getName()));
    }
    return false;
  }

  return true;
}
 
Example 13
Source File: RelMdCollation.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Helper method to determine a
 * {@link org.apache.calcite.rel.core.Values}'s collation.
 *
 * <p>We actually under-report the collations. A Values with 0 or 1 rows - an
 * edge case, but legitimate and very common - is ordered by every permutation
 * of every subset of the columns.
 *
 * <p>So, our algorithm aims to:<ul>
 *   <li>produce at most N collations (where N is the number of columns);
 *   <li>make each collation as long as possible;
 *   <li>do not repeat combinations already emitted -
 *       if we've emitted {@code (a, b)} do not later emit {@code (b, a)};
 *   <li>probe the actual values and make sure that each collation is
 *      consistent with the data
 * </ul>
 *
 * <p>So, for an empty Values with 4 columns, we would emit
 * {@code (a, b, c, d), (b, c, d), (c, d), (d)}. */
public static List<RelCollation> values(RelMetadataQuery mq,
    RelDataType rowType, ImmutableList<ImmutableList<RexLiteral>> tuples) {
  Util.discard(mq); // for future use
  final List<RelCollation> list = new ArrayList<>();
  final int n = rowType.getFieldCount();
  final List<Pair<RelFieldCollation, Ordering<List<RexLiteral>>>> pairs =
      new ArrayList<>();
outer:
  for (int i = 0; i < n; i++) {
    pairs.clear();
    for (int j = i; j < n; j++) {
      final RelFieldCollation fieldCollation = new RelFieldCollation(j);
      Ordering<List<RexLiteral>> comparator = comparator(fieldCollation);
      Ordering<List<RexLiteral>> ordering;
      if (pairs.isEmpty()) {
        ordering = comparator;
      } else {
        ordering = Util.last(pairs).right.compound(comparator);
      }
      pairs.add(Pair.of(fieldCollation, ordering));
      if (!ordering.isOrdered(tuples)) {
        if (j == i) {
          continue outer;
        }
        pairs.remove(pairs.size() - 1);
      }
    }
    if (!pairs.isEmpty()) {
      list.add(RelCollations.of(Pair.left(pairs)));
    }
  }
  return list;
}
 
Example 14
Source File: LogicalCalc.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Deprecated // to be removed before 2.0
public LogicalCalc(
    RelOptCluster cluster,
    RelTraitSet traitSet,
    RelNode child,
    RexProgram program,
    List<RelCollation> collationList) {
  this(cluster, traitSet, ImmutableList.of(), child, program);
  Util.discard(collationList);
}
 
Example 15
Source File: StreamRules.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override public void onMatch(RelOptRuleCall call) {
  final Delta delta = call.rel(0);
  Util.discard(delta);
  final Aggregate aggregate = call.rel(1);
  final LogicalDelta newDelta =
      LogicalDelta.create(aggregate.getInput());
  final LogicalAggregate newAggregate =
      LogicalAggregate.create(newDelta, aggregate.getGroupSet(),
          aggregate.groupSets, aggregate.getAggCallList());
  call.transformTo(newAggregate);
}
 
Example 16
Source File: SqlBetweenOperator.java    From calcite with Apache License 2.0 4 votes vote down vote up
public String getSignatureTemplate(final int operandsCount) {
  Util.discard(operandsCount);
  return "{1} {0} {2} AND {3}";
}
 
Example 17
Source File: JdbcRules.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Deprecated // to be removed before 2.0
public JdbcProject(RelOptCluster cluster, RelTraitSet traitSet,
    RelNode input, List<RexNode> projects, RelDataType rowType, int flags) {
  this(cluster, traitSet, input, projects, rowType);
  Util.discard(flags);
}
 
Example 18
Source File: JdbcImplementor.java    From calcite with Apache License 2.0 4 votes vote down vote up
public JdbcImplementor(SqlDialect dialect, JavaTypeFactory typeFactory) {
  super(dialect);
  Util.discard(typeFactory);
}
 
Example 19
Source File: RexUtil.java    From calcite with Apache License 2.0 4 votes vote down vote up
SubExprExistsException(RexNode expr) {
  Util.discard(expr);
}
 
Example 20
Source File: RelFieldTrimmer.java    From Bats with Apache License 2.0 3 votes vote down vote up
/**
 * Visit method, per {@link org.apache.calcite.util.ReflectiveVisitor}.
 *
 * <p>This method is invoked reflectively, so there may not be any apparent
 * calls to it. The class (or derived classes) may contain overloads of
 * this method with more specific types for the {@code rel} parameter.
 *
 * <p>Returns a pair: the relational expression created, and the mapping
 * between the original fields and the fields of the newly created
 * relational expression.
 *
 * @param rel        Relational expression
 * @param fieldsUsed Fields needed by the consumer
 * @return relational expression and mapping
 */
public TrimResult trimFields(RelNode rel, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) {
    // We don't know how to trim this kind of relational expression, so give
    // it back intact.
    Util.discard(fieldsUsed);
    return result(rel, Mappings.createIdentity(rel.getRowType().getFieldCount()));
}