use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project calcite by apache.
the class SqlTypeNameTest method testLongvarbinary.
@Test
public void testLongvarbinary() {
SqlTypeName tn = SqlTypeName.getNameForJdbcType(Types.LONGVARBINARY);
assertEquals("LONGVARBINARY did not map to null", null, tn);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project calcite by apache.
the class SqlTypeNameTest method testOther.
@Test
public void testOther() {
SqlTypeName tn = SqlTypeName.getNameForJdbcType(Types.OTHER);
assertEquals("OTHER did not map to null", null, tn);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project calcite by apache.
the class SqlTypeNameTest method testBinary.
@Test
public void testBinary() {
SqlTypeName tn = SqlTypeName.getNameForJdbcType(Types.BINARY);
assertEquals("BINARY did not map to BINARY", SqlTypeName.BINARY, tn);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project calcite by apache.
the class SqlTypeNameTest method testBoolean.
@Test
public void testBoolean() {
SqlTypeName tn = SqlTypeName.getNameForJdbcType(Types.BOOLEAN);
assertEquals("BOOLEAN did not map to BOOLEAN", SqlTypeName.BOOLEAN, tn);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeName in project calcite by apache.
the class DruidQuery method computeDruidJsonAgg.
/**
* Translates aggregate calls to Druid {@link JsonAggregation}s when
* possible.
*
* @param aggCalls List of AggregateCalls to translate
* @param aggNames List of aggregate names
* @param project Input project under the aggregate calls,
* or null if we have {@link TableScan} immediately under the
* {@link Aggregate}
* @param druidQuery Druid Query Rel
*
* @return List of valid Druid {@link JsonAggregation}s, or null if any of the
* aggregates is not supported
*/
@Nullable
protected static List<JsonAggregation> computeDruidJsonAgg(List<AggregateCall> aggCalls, List<String> aggNames, @Nullable Project project, DruidQuery druidQuery) {
final List<JsonAggregation> aggregations = new ArrayList<>();
for (Pair<AggregateCall, String> agg : Pair.zip(aggCalls, aggNames)) {
final String fieldName;
final String expression;
final AggregateCall aggCall = agg.left;
final RexNode filterNode;
// Type check First
final RelDataType type = aggCall.getType();
final SqlTypeName sqlTypeName = type.getSqlTypeName();
final boolean isNotAcceptedType;
if (SqlTypeFamily.APPROXIMATE_NUMERIC.getTypeNames().contains(sqlTypeName) || SqlTypeFamily.INTEGER.getTypeNames().contains(sqlTypeName)) {
isNotAcceptedType = false;
} else if (SqlTypeFamily.EXACT_NUMERIC.getTypeNames().contains(sqlTypeName) && (type.getScale() == 0 || druidQuery.getConnectionConfig().approximateDecimal())) {
// Decimal, If scale is zero or we allow approximating decimal, we can proceed
isNotAcceptedType = false;
} else {
isNotAcceptedType = true;
}
if (isNotAcceptedType) {
return null;
}
// Extract filters
if (project != null && aggCall.hasFilter()) {
filterNode = project.getProjects().get(aggCall.filterArg);
} else {
filterNode = null;
}
if (aggCall.getArgList().size() == 0) {
fieldName = null;
expression = null;
} else {
int index = Iterables.getOnlyElement(aggCall.getArgList());
if (project == null) {
fieldName = druidQuery.table.getRowType().getFieldNames().get(index);
expression = null;
} else {
final RexNode rexNode = project.getProjects().get(index);
final RelDataType inputRowType = project.getInput().getRowType();
if (rexNode.isA(SqlKind.INPUT_REF)) {
expression = null;
fieldName = extractColumnName(rexNode, inputRowType, druidQuery);
} else {
expression = DruidExpressions.toDruidExpression(rexNode, inputRowType, druidQuery);
if (Strings.isNullOrEmpty(expression)) {
return null;
}
fieldName = null;
}
}
// One should be not null and the other should be null.
assert expression == null ^ fieldName == null;
}
final JsonAggregation jsonAggregation = getJsonAggregation(agg.right, agg.left, filterNode, fieldName, expression, druidQuery);
if (jsonAggregation == null) {
return null;
}
aggregations.add(jsonAggregation);
}
return aggregations;
}
Aggregations