use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlAggFunction in project storm by apache.
the class RelNodeCompiler method aggregate.
private void aggregate(AggregateCall call) {
SqlAggFunction aggFunction = call.getAggregation();
String aggregationName = call.getAggregation().getName();
Type ty = typeFactory.getJavaClass(call.getType());
if (call.getArgList().size() != 1) {
if (aggregationName.equals("COUNT")) {
if (call.getArgList().size() != 0) {
throw new UnsupportedOperationException("Count with nullable fields");
}
}
}
if (aggFunction instanceof SqlUserDefinedAggFunction) {
AggregateFunction aggregateFunction = ((SqlUserDefinedAggFunction) aggFunction).function;
doAggregate((AggregateFunctionImpl) aggregateFunction, reserveAggVarName(call), ty, call.getArgList());
} else {
List<BuiltinAggregateFunctions.TypeClass> typeClasses = BuiltinAggregateFunctions.TABLE.get(aggregationName);
if (typeClasses == null) {
throw new UnsupportedOperationException(aggregationName + " Not implemented");
}
doAggregate(AggregateFunctionImpl.create(findMatchingClass(aggregationName, typeClasses, ty)), reserveAggVarName(call), ty, call.getArgList());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlAggFunction in project lucene-solr by apache.
the class SolrAggregate method toSolrMetric.
private Pair<String, String> toSolrMetric(Implementor implementor, AggregateCall aggCall, List<String> inNames) {
SqlAggFunction aggregation = aggCall.getAggregation();
List<Integer> args = aggCall.getArgList();
switch(args.size()) {
case 0:
if (aggregation.equals(SqlStdOperatorTable.COUNT)) {
return new Pair<>(aggregation.getName(), "*");
}
case 1:
String inName = inNames.get(args.get(0));
String name = implementor.fieldMappings.getOrDefault(inName, inName);
if (SUPPORTED_AGGREGATIONS.contains(aggregation)) {
return new Pair<>(aggregation.getName(), name);
}
default:
throw new AssertionError("Invalid aggregation " + aggregation + " with args " + args + " with names" + inNames);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlAggFunction in project calcite by apache.
the class RelJsonReader method toAggCall.
private AggregateCall toAggCall(Map<String, Object> jsonAggCall) {
final String aggName = (String) jsonAggCall.get("agg");
final SqlAggFunction aggregation = relJson.toAggregation(aggName, jsonAggCall);
final Boolean distinct = (Boolean) jsonAggCall.get("distinct");
@SuppressWarnings("unchecked") final List<Integer> operands = (List<Integer>) jsonAggCall.get("operands");
final Integer filterOperand = (Integer) jsonAggCall.get("filter");
final RelDataType type = relJson.toType(cluster.getTypeFactory(), jsonAggCall.get("type"));
return AggregateCall.create(aggregation, distinct, false, operands, filterOperand == null ? -1 : filterOperand, type, null);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlAggFunction in project calcite by apache.
the class Aggregate method typeMatchesInferred.
/**
* Returns whether the inferred type of an {@link AggregateCall} matches the
* type it was given when it was created.
*
* @param aggCall Aggregate call
* @param litmus What to do if an error is detected (types do not match)
* @return Whether the inferred and declared types match
*/
private boolean typeMatchesInferred(final AggregateCall aggCall, final Litmus litmus) {
SqlAggFunction aggFunction = aggCall.getAggregation();
AggCallBinding callBinding = aggCall.createBinding(this);
RelDataType type = aggFunction.inferReturnType(callBinding);
RelDataType expectedType = aggCall.type;
return RelOptUtil.eq("aggCall type", expectedType, "inferred type", type, litmus);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlAggFunction in project calcite by apache.
the class SqlOperatorBaseTest method testArgumentBounds.
/**
* Test that calls all operators with all possible argument types, and for
* each type, with a set of tricky values.
*/
@Test
public void testArgumentBounds() {
if (!CalciteAssert.ENABLE_SLOW) {
return;
}
final SqlValidatorImpl validator = (SqlValidatorImpl) tester.getValidator();
final SqlValidatorScope scope = validator.getEmptyScope();
final RelDataTypeFactory typeFactory = validator.getTypeFactory();
final Builder builder = new Builder(typeFactory);
builder.add0(SqlTypeName.BOOLEAN, true, false);
builder.add0(SqlTypeName.TINYINT, 0, 1, -3, Byte.MAX_VALUE, Byte.MIN_VALUE);
builder.add0(SqlTypeName.SMALLINT, 0, 1, -4, Short.MAX_VALUE, Short.MIN_VALUE);
builder.add0(SqlTypeName.INTEGER, 0, 1, -2, Integer.MIN_VALUE, Integer.MAX_VALUE);
builder.add0(SqlTypeName.BIGINT, 0, 1, -5, Integer.MAX_VALUE, Long.MAX_VALUE, Long.MIN_VALUE);
builder.add1(SqlTypeName.VARCHAR, 11, "", " ", "hello world");
builder.add1(SqlTypeName.CHAR, 5, "", "e", "hello");
builder.add0(SqlTypeName.TIMESTAMP, 0L, DateTimeUtils.MILLIS_PER_DAY);
for (SqlOperator op : SqlStdOperatorTable.instance().getOperatorList()) {
switch(op.getKind()) {
// can't handle the flag argument
case TRIM:
case EXISTS:
continue;
}
switch(op.getSyntax()) {
case SPECIAL:
continue;
}
final SqlOperandTypeChecker typeChecker = op.getOperandTypeChecker();
if (typeChecker == null) {
continue;
}
final SqlOperandCountRange range = typeChecker.getOperandCountRange();
for (int n = range.getMin(), max = range.getMax(); n <= max; n++) {
final List<List<ValueType>> argValues = Collections.nCopies(n, builder.values);
for (final List<ValueType> args : Linq4j.product(argValues)) {
SqlNodeList nodeList = new SqlNodeList(SqlParserPos.ZERO);
int nullCount = 0;
for (ValueType arg : args) {
if (arg.value == null) {
++nullCount;
}
nodeList.add(arg.node);
}
final SqlCall call = op.createCall(nodeList);
final SqlCallBinding binding = new SqlCallBinding(validator, scope, call);
if (!typeChecker.checkOperandTypes(binding, false)) {
continue;
}
final SqlPrettyWriter writer = new SqlPrettyWriter(CalciteSqlDialect.DEFAULT);
op.unparse(writer, call, 0, 0);
final String s = writer.toSqlString().toString();
if (s.startsWith("OVERLAY(") || s.contains(" / 0") || s.matches("MOD\\(.*, 0\\)")) {
continue;
}
final Strong.Policy policy = Strong.policy(op.kind);
try {
if (nullCount > 0 && policy == Strong.Policy.ANY) {
tester.checkNull(s);
} else {
final String query;
if (op instanceof SqlAggFunction) {
if (op.requiresOrder()) {
query = "SELECT " + s + " OVER () FROM (VALUES (1))";
} else {
query = "SELECT " + s + " FROM (VALUES (1))";
}
} else {
query = SqlTesterImpl.buildQuery(s);
}
tester.check(query, SqlTests.ANY_TYPE_CHECKER, SqlTests.ANY_PARAMETER_CHECKER, SqlTests.ANY_RESULT_CHECKER);
}
} catch (Error e) {
System.out.println(s + ": " + e.getMessage());
throw e;
} catch (Exception e) {
System.out.println("Failed: " + s + ": " + e.getMessage());
}
}
}
}
}
Aggregations