use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class SqlDotOperator method deriveType.
@Override
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
RelDataType nodeType = validator.deriveType(scope, call.getOperandList().get(0));
assert nodeType != null;
final String fieldName = call.getOperandList().get(1).toString();
RelDataTypeField field = nodeType.getField(fieldName, false, false);
if (field == null) {
throw SqlUtil.newContextException(SqlParserPos.ZERO, Static.RESOURCE.unknownField(fieldName));
}
RelDataType type = field.getType();
// Validate and determine coercibility and resulting collation
// name of binary operator if needed.
type = adjustType(validator, call, type);
SqlValidatorUtil.checkCharsetAndCollateConsistentIfCharType(type);
return type;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class MockCatalogReader method deduceMonotonicity.
private static List<RelCollation> deduceMonotonicity(Prepare.PreparingTable table) {
final List<RelCollation> collationList = Lists.newArrayList();
// Deduce which fields the table is sorted on.
int i = -1;
for (RelDataTypeField field : table.getRowType().getFieldList()) {
++i;
final SqlMonotonicity monotonicity = table.getMonotonicity(field.getName());
if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) {
final RelFieldCollation.Direction direction = monotonicity.isDecreasing() ? RelFieldCollation.Direction.DESCENDING : RelFieldCollation.Direction.ASCENDING;
collationList.add(RelCollations.of(new RelFieldCollation(i, direction)));
}
}
return collationList;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class RelBuilderTest method testAlias.
@Test
public void testAlias() {
// Equivalent SQL:
// SELECT *
// FROM emp AS e, dept
// WHERE e.deptno = dept.deptno
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root = builder.scan("EMP").as("e").scan("DEPT").join(JoinRelType.LEFT).filter(builder.equals(builder.field("e", "DEPTNO"), builder.field("DEPT", "DEPTNO"))).project(builder.field("e", "ENAME"), builder.field("DEPT", "DNAME")).build();
final String expected = "LogicalProject(ENAME=[$1], DNAME=[$9])\n" + " LogicalFilter(condition=[=($7, $8)])\n" + " LogicalJoin(condition=[true], joinType=[left])\n" + " LogicalTableScan(table=[[scott, EMP]])\n" + " LogicalTableScan(table=[[scott, DEPT]])\n";
assertThat(root, hasTree(expected));
final RelDataTypeField field = root.getRowType().getFieldList().get(1);
assertThat(field.getName(), is("DNAME"));
assertThat(field.getType().isNullable(), is(true));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class SqlTesterImpl method getColumnType.
public RelDataType getColumnType(String sql) {
RelDataType rowType = getResultType(sql);
final List<RelDataTypeField> fields = rowType.getFieldList();
assertEquals("expected query to return 1 field", 1, fields.size());
return fields.get(0).getType();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class GeodeUtils method handleJavaObjectEntry.
private static Object handleJavaObjectEntry(List<RelDataTypeField> relDataTypeFields, Object obj) {
Class<?> clazz = obj.getClass();
if (relDataTypeFields.size() == 1) {
try {
Field javaField = clazz.getDeclaredField(relDataTypeFields.get(0).getName());
javaField.setAccessible(true);
return javaField.get(obj);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Object[] values = new Object[relDataTypeFields.size()];
int index = 0;
for (RelDataTypeField relDataTypeField : relDataTypeFields) {
try {
Field javaField = clazz.getDeclaredField(relDataTypeField.getName());
javaField.setAccessible(true);
values[index++] = javaField.get(obj);
} catch (Exception e) {
e.printStackTrace();
}
}
return values;
}
Aggregations