Search in sources :

Example 1 with JsonObjectMapperProvider

use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.

the class MetadataManager method createTestingViewCodec.

private static JsonCodec<ViewDefinition> createTestingViewCodec(FunctionAndTypeManager functionAndTypeManager) {
    JsonObjectMapperProvider provider = new JsonObjectMapperProvider();
    provider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(functionAndTypeManager)));
    return new JsonCodecFactory(provider).jsonCodec(ViewDefinition.class);
}
Also used : OperatorType(com.facebook.presto.common.function.OperatorType) Type(com.facebook.presto.common.type.Type) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) JsonCodecFactory(com.facebook.airlift.json.JsonCodecFactory)

Example 2 with JsonObjectMapperProvider

use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.

the class TestCustomDateTimeJsonFieldDecoder method testInvalidFormatHint.

@Test
public void testInvalidFormatHint() {
    DecoderTestColumnHandle columnHandle = new DecoderTestColumnHandle(0, "some_column", TIMESTAMP, "mappedField", "custom-date-time", "XXMM/yyyy/dd H:m:sXX", false, false, false);
    assertThatThrownBy(() -> new JsonRowDecoderFactory(new JsonObjectMapperProvider().get()).create(emptyMap(), ImmutableSet.of(columnHandle))).isInstanceOf(PrestoException.class).hasMessageMatching("invalid joda pattern 'XXMM/yyyy/dd H:m:sXX' passed as format hint for column 'some_column'");
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) PrestoException(com.facebook.presto.spi.PrestoException) Test(org.testng.annotations.Test)

Example 3 with JsonObjectMapperProvider

use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.

the class RecordingHiveMetastore method writeRecording.

@Managed
public void writeRecording() throws IOException {
    if (replay) {
        throw new IllegalStateException("Cannot write recording in replay mode");
    }
    Recording recording = new Recording(allDatabases, allRoles, toPairs(databaseCache), toPairs(tableCache), toPairs(supportedColumnStatisticsCache), toPairs(tableStatisticsCache), toPairs(partitionStatisticsCache), toPairs(allTablesCache), toPairs(allViewsCache), toPairs(partitionCache), toPairs(partitionNamesCache), toPairs(partitionNamesByFilterCache), toPairs(partitionsByNamesCache), toPairs(tablePrivilegesCache), toPairs(roleGrantsCache));
    new JsonObjectMapperProvider().get().writerWithDefaultPrettyPrinter().writeValue(new File(recordingPath), recording);
}
Also used : JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) File(java.io.File) Managed(org.weakref.jmx.Managed)

Example 4 with JsonObjectMapperProvider

use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.

the class RecordingHiveMetastore method loadRecording.

@VisibleForTesting
void loadRecording() throws IOException {
    Recording recording = new JsonObjectMapperProvider().get().readValue(new File(recordingPath), Recording.class);
    allDatabases = recording.getAllDatabases();
    allRoles = recording.getAllRoles();
    databaseCache.putAll(toMap(recording.getDatabases()));
    tableCache.putAll(toMap(recording.getTables()));
    supportedColumnStatisticsCache.putAll(toMap(recording.getSupportedColumnStatistics()));
    tableStatisticsCache.putAll(toMap(recording.getTableStatistics()));
    partitionStatisticsCache.putAll(toMap(recording.getPartitionStatistics()));
    allTablesCache.putAll(toMap(recording.getAllTables()));
    allViewsCache.putAll(toMap(recording.getAllViews()));
    partitionCache.putAll(toMap(recording.getPartitions()));
    partitionNamesCache.putAll(toMap(recording.getPartitionNames()));
    partitionNamesByFilterCache.putAll(toMap(recording.getPartitionNamesByFilter()));
    partitionsByNamesCache.putAll(toMap(recording.getPartitionsByNames()));
    tablePrivilegesCache.putAll(toMap(recording.getTablePrivileges()));
    roleGrantsCache.putAll(toMap(recording.getRoleGrants()));
}
Also used : JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) File(java.io.File) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with JsonObjectMapperProvider

use of com.facebook.airlift.json.JsonObjectMapperProvider in project presto by prestodb.

the class TestSignature method testSerializationRoundTrip.

@Test
public void testSerializationRoundTrip() {
    JsonObjectMapperProvider objectMapperProvider = new JsonObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(createTestFunctionAndTypeManager())));
    JsonCodec<Signature> codec = new JsonCodecFactory(objectMapperProvider, true).jsonCodec(Signature.class);
    Signature expected = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "function"), SCALAR, parseTypeSignature(StandardTypes.BIGINT), ImmutableList.of(parseTypeSignature(StandardTypes.BOOLEAN), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.VARCHAR)));
    String json = codec.toJson(expected);
    Signature actual = codec.fromJson(json);
    assertEquals(actual.getNameSuffix(), expected.getNameSuffix());
    assertEquals(actual.getKind(), expected.getKind());
    assertEquals(actual.getReturnType(), expected.getReturnType());
    assertEquals(actual.getArgumentTypes(), expected.getArgumentTypes());
}
Also used : Type(com.facebook.presto.common.type.Type) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) JsonCodecFactory(com.facebook.airlift.json.JsonCodecFactory) Test(org.testng.annotations.Test)

Aggregations

JsonObjectMapperProvider (com.facebook.airlift.json.JsonObjectMapperProvider)19 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 Test (org.testng.annotations.Test)12 Type (com.facebook.presto.common.type.Type)9 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)9 TestingTypeDeserializer (com.facebook.presto.common.type.TestingTypeDeserializer)7 TestingTypeManager (com.facebook.presto.common.type.TestingTypeManager)7 Block (com.facebook.presto.common.block.Block)6 TestingBlockEncodingSerde (com.facebook.presto.common.block.TestingBlockEncodingSerde)6 TestingBlockJsonSerde (com.facebook.presto.common.block.TestingBlockJsonSerde)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 IOException (java.io.IOException)3 JsonCodecFactory (com.facebook.airlift.json.JsonCodecFactory)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 TypeDeserializer (com.facebook.presto.type.TypeDeserializer)2 JsonParser (com.fasterxml.jackson.core.JsonParser)2 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)2 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)2 File (java.io.File)2 Map (java.util.Map)2