use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.
the class TestSortedRangeSet method testJsonSerialization.
@Test
public void testJsonSerialization() throws Exception {
TestingTypeManager typeManager = new TestingTypeManager();
TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
SortedRangeSet set = SortedRangeSet.all(BIGINT);
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
set = SortedRangeSet.none(DOUBLE);
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
set = SortedRangeSet.of(VARCHAR, utf8Slice("abc"));
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
set = SortedRangeSet.of(Range.equal(BOOLEAN, true), Range.equal(BOOLEAN, false));
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
}
use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.
the class TestTupleDomain method testJsonSerialization.
@Test
public void testJsonSerialization() throws Exception {
TestingTypeManager typeManager = new TestingTypeManager();
TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(ColumnHandle.class, new JsonDeserializer<>() {
@Override
public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
return new ObjectMapperProvider().get().readValue(jsonParser, TestingColumnHandle.class);
}
}).addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
TupleDomain<ColumnHandle> tupleDomain = TupleDomain.all();
assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
}));
tupleDomain = TupleDomain.none();
assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
}));
tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.of(A, NullableValue.of(BIGINT, 1L), B, NullableValue.asNull(VARCHAR)));
assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
}));
}
use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.
the class TestDeltaLakePageSink method createPageSink.
private static ConnectorPageSink createPageSink(Path outputPath, DeltaLakeWriterStats stats) {
HiveTransactionHandle transaction = new HiveTransactionHandle(false);
DeltaLakeConfig deltaLakeConfig = new DeltaLakeConfig();
DeltaLakeOutputTableHandle tableHandle = new DeltaLakeOutputTableHandle(SCHEMA_NAME, TABLE_NAME, getColumnHandles(), outputPath.toString(), Optional.of(deltaLakeConfig.getDefaultCheckpointWritingInterval()), true);
DeltaLakePageSinkProvider provider = new DeltaLakePageSinkProvider(new GroupByHashPageIndexerFactory(new JoinCompiler(new TypeOperators()), new BlockTypeOperators()), HDFS_ENVIRONMENT, JsonCodec.jsonCodec(DataFileInfo.class), stats, deltaLakeConfig, new TestingTypeManager(), new NodeVersion("test-version"));
return provider.createPageSink(transaction, SESSION, tableHandle);
}
use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.
the class TestRecordingHiveMetastore method createJsonCodec.
private JsonCodec<HiveMetastoreRecording.Recording> createJsonCodec() {
ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
TypeDeserializer typeDeserializer = new TypeDeserializer(new TestingTypeManager());
objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Block.class, new TestingBlockJsonSerde.Deserializer(new HiveBlockEncodingSerde()), Type.class, typeDeserializer));
objectMapperProvider.setJsonSerializers(ImmutableMap.of(Block.class, new TestingBlockJsonSerde.Serializer(new HiveBlockEncodingSerde())));
JsonCodec<HiveMetastoreRecording.Recording> jsonCodec = new JsonCodecFactory(objectMapperProvider).jsonCodec(HiveMetastoreRecording.Recording.class);
return jsonCodec;
}
use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.
the class TestAvroSchemaConverter method testEmptyFieldStrategy.
@Test
public void testEmptyFieldStrategy() {
Schema schema = SchemaBuilder.record(RECORD_NAME).fields().name("my_int").type().intType().noDefault().name("my_record").type().record("nested_record").fields().endRecord().noDefault().name("my_array").type().array().items().type("nested_record").noDefault().name("my_map").type().map().values().type("nested_record").noDefault().endRecord();
List<Type> typesForIgnoreStrategy = ImmutableList.<Type>builder().add(INTEGER).build();
assertEquals(new AvroSchemaConverter(new TestingTypeManager(), IGNORE).convertAvroSchema(schema), typesForIgnoreStrategy);
assertThatThrownBy(() -> new AvroSchemaConverter(new TestingTypeManager(), FAIL).convertAvroSchema(schema)).isInstanceOf(IllegalStateException.class).hasMessage("Struct type has no valid fields for schema: '%s'", SchemaBuilder.record("nested_record").fields().endRecord());
List<Type> typesForAddDummyStrategy = ImmutableList.<Type>builder().add(INTEGER).add(RowType.from(ImmutableList.<RowType.Field>builder().add(new RowType.Field(Optional.of(DUMMY_FIELD_NAME), BOOLEAN)).build())).add(new ArrayType(RowType.from(ImmutableList.<RowType.Field>builder().add(new RowType.Field(Optional.of(DUMMY_FIELD_NAME), BOOLEAN)).build()))).add(createType(RowType.from(ImmutableList.<RowType.Field>builder().add(new RowType.Field(Optional.of(DUMMY_FIELD_NAME), BOOLEAN)).build()))).build();
assertEquals(new AvroSchemaConverter(new TestingTypeManager(), ADD_DUMMY).convertAvroSchema(schema), typesForAddDummyStrategy);
}
Aggregations