use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlSubstringFunction method checkOperandTypes.
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
SqlValidator validator = callBinding.getValidator();
SqlValidatorScope scope = callBinding.getScope();
final List<SqlNode> operands = callBinding.operands();
int n = operands.size();
assert (3 == n) || (2 == n);
if (!OperandTypes.STRING.checkSingleOperandType(callBinding, operands.get(0), 0, throwOnFailure)) {
return false;
}
if (2 == n) {
if (!OperandTypes.NUMERIC.checkSingleOperandType(callBinding, operands.get(1), 0, throwOnFailure)) {
return false;
}
} else {
RelDataType t1 = validator.deriveType(scope, operands.get(1));
RelDataType t2 = validator.deriveType(scope, operands.get(2));
if (SqlTypeUtil.inCharFamily(t1)) {
if (!OperandTypes.STRING.checkSingleOperandType(callBinding, operands.get(1), 0, throwOnFailure)) {
return false;
}
if (!OperandTypes.STRING.checkSingleOperandType(callBinding, operands.get(2), 0, throwOnFailure)) {
return false;
}
if (!SqlTypeUtil.isCharTypeComparable(callBinding, operands, throwOnFailure)) {
return false;
}
} else {
if (!OperandTypes.NUMERIC.checkSingleOperandType(callBinding, operands.get(1), 0, throwOnFailure)) {
return false;
}
if (!OperandTypes.NUMERIC.checkSingleOperandType(callBinding, operands.get(2), 0, throwOnFailure)) {
return false;
}
}
if (!SqlTypeUtil.inSameFamily(t1, t2)) {
if (throwOnFailure) {
throw callBinding.newValidationSignatureError();
}
return false;
}
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class RelBuilderTest method testConvert.
@Test
public void testConvert() {
final RelBuilder builder = RelBuilder.create(config().build());
RelDataType rowType = builder.getTypeFactory().builder().add("a", SqlTypeName.BIGINT).add("b", SqlTypeName.VARCHAR, 10).add("c", SqlTypeName.VARCHAR, 10).build();
RelNode root = builder.scan("DEPT").convert(rowType, false).build();
final String expected = "" + "LogicalProject(DEPTNO=[CAST($0):BIGINT NOT NULL], DNAME=[CAST($1):VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL], LOC=[CAST($2):VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL])\n" + " LogicalTableScan(table=[[scott, DEPT]])\n";
assertThat(root, hasTree(expected));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class RelBuilderTest method testFilterCastAny.
@Test
public void testFilterCastAny() {
final RelBuilder builder = RelBuilder.create(config().build());
final RelDataType anyType = builder.getTypeFactory().createSqlType(SqlTypeName.ANY);
final RelNode root = builder.scan("EMP").filter(builder.cast(builder.getRexBuilder().makeInputRef(anyType, 0), SqlTypeName.BOOLEAN)).build();
final String expected = "" + "LogicalFilter(condition=[CAST($0):BOOLEAN NOT NULL])\n" + " LogicalTableScan(table=[[scott, EMP]])\n";
assertThat(root, hasTree(expected));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class RelBuilderTest method testValuesAllNull.
@Test
public void testValuesAllNull() {
final RelBuilder builder = RelBuilder.create(config().build());
RelDataType rowType = builder.getTypeFactory().builder().add("a", SqlTypeName.BIGINT).add("a", SqlTypeName.VARCHAR, 10).build();
RelNode root = builder.values(rowType, null, null, 1, null).build();
final String expected = "LogicalValues(tuples=[[{ null, null }, { 1, null }]])\n";
assertThat(root, hasTree(expected));
final String expectedType = "RecordType(BIGINT NOT NULL a, VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL a) NOT NULL";
assertThat(root.getRowType().getFullTypeString(), is(expectedType));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class RelBuilderTest method testConvertRename.
@Test
public void testConvertRename() {
final RelBuilder builder = RelBuilder.create(config().build());
RelDataType rowType = builder.getTypeFactory().builder().add("a", SqlTypeName.BIGINT).add("b", SqlTypeName.VARCHAR, 10).add("c", SqlTypeName.VARCHAR, 10).build();
RelNode root = builder.scan("DEPT").convert(rowType, true).build();
final String expected = "" + "LogicalProject(a=[CAST($0):BIGINT NOT NULL], b=[CAST($1):VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL], c=[CAST($2):VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL])\n" + " LogicalTableScan(table=[[scott, DEPT]])\n";
assertThat(root, hasTree(expected));
}
Aggregations