use of org.apache.calcite.sql.type.BasicSqlType in project calcite by apache.
the class SqlLimitsTest method printLimit.
private void printLimit(PrintWriter pw, String desc, RelDataType type, boolean sign, SqlTypeName.Limit limit, boolean beyond) {
Object o = ((BasicSqlType) type).getLimit(sign, limit, beyond);
if (o == null) {
return;
}
pw.print(desc);
String s;
if (o instanceof byte[]) {
int k = 0;
StringBuilder buf = new StringBuilder("{");
for (byte b : (byte[]) o) {
if (k++ > 0) {
buf.append(", ");
}
buf.append(Integer.toHexString(b & 0xff));
}
buf.append("}");
s = buf.toString();
} else if (o instanceof Calendar) {
Calendar calendar = (Calendar) o;
DateFormat dateFormat = getDateFormat(type.getSqlTypeName());
dateFormat.setTimeZone(DateTimeUtils.UTC_ZONE);
s = dateFormat.format(calendar.getTime());
} else {
s = o.toString();
}
pw.print(s);
SqlLiteral literal = type.getSqlTypeName().createLiteral(o, SqlParserPos.ZERO);
pw.print("; as SQL: ");
pw.print(literal.toSqlString(AnsiSqlDialect.DEFAULT));
pw.println();
}
use of org.apache.calcite.sql.type.BasicSqlType in project druid by druid-io.
the class DruidRexExecutorTest method testArrayOfLongsReduction.
@Test
public void testArrayOfLongsReduction() {
DruidRexExecutor rexy = new DruidRexExecutor(PLANNER_CONTEXT);
List<RexNode> reduced = new ArrayList<>();
BasicSqlType basicSqlType = new BasicSqlType(DruidTypeSystem.INSTANCE, SqlTypeName.INTEGER);
ArraySqlType arraySqlType = new ArraySqlType(basicSqlType, false);
List<BigDecimal> elements = ImmutableList.of(BigDecimal.valueOf(50), BigDecimal.valueOf(12));
RexNode literal = rexBuilder.makeLiteral(elements, arraySqlType, true);
rexy.reduce(rexBuilder, ImmutableList.of(literal), reduced);
Assert.assertEquals(1, reduced.size());
Assert.assertEquals(DruidExpression.ofExpression(ColumnType.LONG_ARRAY, DruidExpression.functionCall("array"), ImmutableList.of(DruidExpression.ofLiteral(ColumnType.LONG, "50"), DruidExpression.ofLiteral(ColumnType.LONG, "12"))), Expressions.toDruidExpression(PLANNER_CONTEXT, RowSignature.empty(), reduced.get(0)));
}
use of org.apache.calcite.sql.type.BasicSqlType in project druid by druid-io.
the class DruidRexExecutorTest method testArrayOfDoublesReduction.
@Test
public void testArrayOfDoublesReduction() {
DruidRexExecutor rexy = new DruidRexExecutor(PLANNER_CONTEXT);
List<RexNode> reduced = new ArrayList<>();
BasicSqlType basicSqlType = new BasicSqlType(DruidTypeSystem.INSTANCE, SqlTypeName.DECIMAL);
ArraySqlType arraySqlType = new ArraySqlType(basicSqlType, false);
List<BigDecimal> elements = ImmutableList.of(BigDecimal.valueOf(50.12), BigDecimal.valueOf(12.1));
RexNode literal = rexBuilder.makeLiteral(elements, arraySqlType, true);
rexy.reduce(rexBuilder, ImmutableList.of(literal), reduced);
Assert.assertEquals(1, reduced.size());
Assert.assertEquals(DruidExpression.ofExpression(ColumnType.DOUBLE_ARRAY, DruidExpression.functionCall("array"), ImmutableList.of(DruidExpression.ofLiteral(ColumnType.DOUBLE, "50.12"), DruidExpression.ofLiteral(ColumnType.DOUBLE, "12.1"))), Expressions.toDruidExpression(PLANNER_CONTEXT, RowSignature.empty(), reduced.get(0)));
}
use of org.apache.calcite.sql.type.BasicSqlType in project samza by apache.
the class CheckerTest method testCheckOperandTypesShouldReturnTrueOnAnyTypeInArg.
@Test
public void testCheckOperandTypesShouldReturnTrueOnAnyTypeInArg() throws NoSuchMethodException {
Method udfMethod = TestUdfWithAnyType.class.getMethod("execute", Object.class);
UdfMetadata udfMetadata = new UdfMetadata("TestUdfWithAnyType", "TestUDFClass", udfMethod, new MapConfig(), ImmutableList.of(SamzaSqlFieldType.ANY), SamzaSqlFieldType.INT64, false);
Checker operandTypeChecker = Checker.getChecker(1, 3, udfMetadata);
SqlCallBinding callBinding = Mockito.mock(SqlCallBinding.class);
Mockito.when(callBinding.getOperandCount()).thenReturn(1);
Mockito.when(callBinding.getOperandType(0)).thenReturn(new BasicSqlType(RelDataTypeSystem.DEFAULT, SqlTypeName.ARRAY));
assertTrue(operandTypeChecker.checkOperandTypes(callBinding, true));
}
use of org.apache.calcite.sql.type.BasicSqlType in project samza by apache.
the class CheckerTest method testCheckOperandTypesShouldReturnTrueWhenArgumentCheckIsDisabled.
@Test
public void testCheckOperandTypesShouldReturnTrueWhenArgumentCheckIsDisabled() throws NoSuchMethodException {
Method udfMethod = TestUdfWithWrongTypes.class.getMethod("execute", String.class);
UdfMetadata udfMetadata = new UdfMetadata("TestUdfWithWrongTypes", "TestUDFClass", udfMethod, new MapConfig(), ImmutableList.of(SamzaSqlFieldType.INT32), SamzaSqlFieldType.INT64, true);
Checker operandTypeChecker = Checker.getChecker(1, 3, udfMetadata);
SqlCallBinding callBinding = Mockito.mock(SqlCallBinding.class);
Mockito.when(callBinding.getOperandCount()).thenReturn(1);
Mockito.when(callBinding.getOperandType(0)).thenReturn(new BasicSqlType(RelDataTypeSystem.DEFAULT, SqlTypeName.VARCHAR, 12));
assertTrue(operandTypeChecker.checkOperandTypes(callBinding, true));
}
Aggregations