use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestTypeSignature method assertRowSignature.
private static void assertRowSignature(String typeName, Set<String> literalParameters, TypeSignature expectedSignature) {
TypeSignature signature = parseTypeSignature(typeName, literalParameters);
assertEquals(signature, expectedSignature);
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestTypeSignature method parseSignatureWithLiterals.
@Test
public void parseSignatureWithLiterals() {
TypeSignature result = new TypeSignature("decimal", typeVariable("X"), numericParameter(42));
assertEquals(result.getParameters().size(), 2);
assertEquals(result.getParameters().get(0).isVariable(), true);
assertEquals(result.getParameters().get(1).isLongLiteral(), true);
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class DecimalOperators method modulusSignatureBuilder.
public static SignatureBuilder modulusSignatureBuilder() {
TypeSignature decimalLeftSignature = new TypeSignature("decimal", typeVariable("a_precision"), typeVariable("a_scale"));
TypeSignature decimalRightSignature = new TypeSignature("decimal", typeVariable("b_precision"), typeVariable("b_scale"));
TypeSignature decimalResultSignature = new TypeSignature("decimal", typeVariable("r_precision"), typeVariable("r_scale"));
return Signature.builder().longVariableConstraints(longVariableExpression("r_precision", "min(b_precision - b_scale, a_precision - a_scale) + max(a_scale, b_scale)"), longVariableExpression("r_scale", "max(a_scale, b_scale)")).argumentTypes(decimalLeftSignature, decimalRightSignature).returnType(decimalResultSignature);
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class RowParametricType method createType.
@Override
public Type createType(TypeManager typeManager, List<TypeParameter> parameters) {
checkArgument(!parameters.isEmpty(), "Row type must have at least one parameter");
checkArgument(parameters.stream().allMatch(parameter -> parameter.getKind() == ParameterKind.NAMED_TYPE), "Expected only named types as a parameters, got %s", parameters);
List<TypeSignatureParameter> typeSignatureParameters = parameters.stream().map(TypeParameter::getNamedType).map(parameter -> TypeSignatureParameter.namedTypeParameter(new NamedTypeSignature(parameter.getName(), parameter.getType().getTypeSignature()))).collect(toList());
List<RowType.Field> fields = parameters.stream().map(TypeParameter::getNamedType).map(parameter -> new RowType.Field(parameter.getName().map(RowFieldName::getName), parameter.getType())).collect(toList());
return RowType.createWithTypeSignature(new TypeSignature(StandardTypes.ROW, typeSignatureParameters), fields);
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestFixJsonDataUtils method testFixData.
@Test
public void testFixData() {
assertQueryResult(BIGINT.getTypeSignature(), 1000, 1000L);
assertQueryResult(INTEGER.getTypeSignature(), 100, 100);
assertQueryResult(SMALLINT.getTypeSignature(), 10, (short) 10);
assertQueryResult(TINYINT.getTypeSignature(), 1, (byte) 1);
assertQueryResult(BOOLEAN.getTypeSignature(), true, true);
assertQueryResult(DATE.getTypeSignature(), "2017-07-01", "2017-07-01");
assertQueryResult(createDecimalType().getTypeSignature(), "2.15", "2.15");
assertQueryResult(REAL.getTypeSignature(), 100.23456, (float) 100.23456);
assertQueryResult(DOUBLE.getTypeSignature(), 100.23456D, 100.23456);
assertQueryResult(new TypeSignature(INTERVAL_DAY_TO_SECOND), "INTERVAL '2' DAY", "INTERVAL '2' DAY");
assertQueryResult(new TypeSignature(INTERVAL_YEAR_TO_MONTH), "INTERVAL '3' MONTH", "INTERVAL '3' MONTH");
assertQueryResult(TIMESTAMP_MILLIS.getTypeSignature(), "2001-08-22 03:04:05.321", "2001-08-22 03:04:05.321");
assertQueryResult(TIMESTAMP_WITH_TIME_ZONE.getTypeSignature(), "2001-08-22 03:04:05.321 America/Los_Angeles", "2001-08-22 03:04:05.321 America/Los_Angeles");
assertQueryResult(TIME.getTypeSignature(), "01:02:03.456", "01:02:03.456");
assertQueryResult(TIMESTAMP_WITH_TIME_ZONE.getTypeSignature(), "01:02:03.456 America/Los_Angeles", "01:02:03.456 America/Los_Angeles");
assertQueryResult(VARBINARY.getTypeSignature(), "garbage", Base64.getDecoder().decode("garbage"));
assertQueryResult(VARCHAR.getTypeSignature(), "teststring", "teststring");
assertQueryResult(createCharType(3).getTypeSignature(), "abc", "abc");
assertQueryResult(RowType.from(ImmutableList.of(field("foo", BIGINT), field("bar", BIGINT))).getTypeSignature(), ImmutableList.of(1, 2), Row.builder().addField("foo", 1L).addField("bar", 2L).build());
assertQueryResult(arrayType(BIGINT.getTypeSignature()), ImmutableList.of(1, 2, 4), ImmutableList.of(1L, 2L, 4L));
assertQueryResult(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()), ImmutableMap.of(1, 3, 2, 4), ImmutableMap.of(1L, 3L, 2L, 4L));
assertQueryResult(new TypeSignature(JSON), "{\"json\": {\"a\": 1}}", "{\"json\": {\"a\": 1}}");
assertQueryResult(new TypeSignature(IPADDRESS), "1.2.3.4", "1.2.3.4");
assertQueryResult(new TypeSignature(UUID), "0397e63b-2b78-4b7b-9c87-e085fa225dd8", "0397e63b-2b78-4b7b-9c87-e085fa225dd8");
assertQueryResult(new TypeSignature("Geometry"), "POINT (1.2 3.4)", "POINT (1.2 3.4)");
assertQueryResult(mapType(new TypeSignature("BingTile"), BIGINT.getTypeSignature()), ImmutableMap.of("BingTile{x=1, y=2, zoom_level=10}", 1), ImmutableMap.of("BingTile{x=1, y=2, zoom_level=10}", 1L));
}
Aggregations