Java Code Examples for io.airlift.json.JsonCodec#fromJson()

The following examples show how to use io.airlift.json.JsonCodec#fromJson() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSignature.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializationRoundTrip()
{
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(
            Type.class, new TypeDeserializer(createTestMetadataManager()),
            TypeSignature.class, new TypeSignatureDeserializer()));
    JsonCodec<Signature> codec = new JsonCodecFactory(objectMapperProvider, true).jsonCodec(Signature.class);

    Signature expected = new Signature(
            "function",
            BIGINT.getTypeSignature(),
            ImmutableList.of(BOOLEAN.getTypeSignature(), DOUBLE.getTypeSignature(), VARCHAR.getTypeSignature()));

    String json = codec.toJson(expected);
    Signature actual = codec.fromJson(json);

    assertEquals(actual.getName(), expected.getName());
    assertEquals(actual.getReturnType(), expected.getReturnType());
    assertEquals(actual.getArgumentTypes(), expected.getArgumentTypes());
}
 
Example 2
Source File: TestHiveColumnHandle.java    From presto with Apache License 2.0 6 votes vote down vote up
private void testRoundTrip(HiveColumnHandle expected)
{
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new HiveModule.TypeDeserializer(new InternalTypeManager(createTestMetadataManager()))));
    JsonCodec<HiveColumnHandle> codec = new JsonCodecFactory(objectMapperProvider).jsonCodec(HiveColumnHandle.class);

    String json = codec.toJson(expected);
    HiveColumnHandle actual = codec.fromJson(json);

    assertEquals(actual.getBaseColumnName(), expected.getBaseColumnName());
    assertEquals(actual.getBaseHiveColumnIndex(), expected.getBaseHiveColumnIndex());
    assertEquals(actual.getBaseType(), expected.getBaseType());
    assertEquals(actual.getBaseHiveType(), expected.getBaseHiveType());

    assertEquals(actual.getName(), expected.getName());
    assertEquals(actual.getType(), expected.getType());
    assertEquals(actual.getHiveType(), expected.getHiveType());

    assertEquals(actual.getHiveColumnProjectionInfo(), expected.getHiveColumnProjectionInfo());
    assertEquals(actual.isPartitionKey(), expected.isPartitionKey());
}
 
Example 3
Source File: TestSystemSplit.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization()
{
    SystemSplit expected = new SystemSplit(HostAddress.fromParts("127.0.0.1", 0), TupleDomain.all());

    JsonCodec<SystemSplit> codec = jsonCodec(SystemSplit.class);
    SystemSplit actual = codec.fromJson(codec.toJson(expected));

    assertEquals(actual.getAddresses(), expected.getAddresses());
    assertEquals(actual.getConstraint(), expected.getConstraint());
}
 
Example 4
Source File: TestPinotTableHandle.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonRoundTrip()
{
    JsonCodec<PinotTableHandle> codec = jsonCodec(PinotTableHandle.class);
    String json = codec.toJson(tableHandle);
    PinotTableHandle copy = codec.fromJson(json);
    assertEquals(copy, tableHandle);
}
 
Example 5
Source File: TestQueryStats.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJson()
{
    JsonCodec<QueryStats> codec = JsonCodec.jsonCodec(QueryStats.class);

    String json = codec.toJson(EXPECTED);
    QueryStats actual = codec.fromJson(json);

    assertExpectedQueryStats(actual);
}
 
Example 6
Source File: TestStageStats.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJson()
{
    JsonCodec<StageStats> codec = JsonCodec.jsonCodec(StageStats.class);

    String json = codec.toJson(EXPECTED);
    StageStats actual = codec.fromJson(json);

    assertExpectedStageStats(actual);
}
 
Example 7
Source File: TestDriverStats.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJson()
{
    JsonCodec<DriverStats> codec = JsonCodec.jsonCodec(DriverStats.class);

    String json = codec.toJson(EXPECTED);
    DriverStats actual = codec.fromJson(json);

    assertExpectedDriverStats(actual);
}
 
Example 8
Source File: TestTaskStats.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJson()
{
    JsonCodec<TaskStats> codec = JsonCodec.jsonCodec(TaskStats.class);

    String json = codec.toJson(EXPECTED);
    TaskStats actual = codec.fromJson(json);

    assertExpectedTaskStats(actual);
}
 
Example 9
Source File: TestOperatorStats.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJson()
{
    JsonCodec<OperatorStats> codec = JsonCodec.jsonCodec(OperatorStats.class);

    String json = codec.toJson(EXPECTED);
    OperatorStats actual = codec.fromJson(json);

    assertExpectedOperatorStats(actual);
}
 
Example 10
Source File: TestUtils.java    From presto with Apache License 2.0 5 votes vote down vote up
public static Map.Entry<SchemaTableName, KafkaTopicDescription> loadTpchTopicDescription(JsonCodec<KafkaTopicDescription> topicDescriptionJsonCodec, String topicName, SchemaTableName schemaTableName)
        throws IOException
{
    KafkaTopicDescription tpchTemplate = topicDescriptionJsonCodec.fromJson(ByteStreams.toByteArray(TestUtils.class.getResourceAsStream(format("/tpch/%s.json", schemaTableName.getTableName()))));

    return new AbstractMap.SimpleImmutableEntry<>(
            schemaTableName,
            new KafkaTopicDescription(schemaTableName.getTableName(), Optional.of(schemaTableName.getSchemaName()), topicName, tpchTemplate.getKey(), tpchTemplate.getMessage()));
}
 
Example 11
Source File: TestJdbcSplit.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonRoundTrip()
{
    JsonCodec<JdbcSplit> codec = jsonCodec(JdbcSplit.class);
    String json = codec.toJson(split);
    JdbcSplit copy = codec.fromJson(json);
    assertEquals(copy.getAdditionalPredicate(), split.getAdditionalPredicate());

    assertEquals(copy.getAddresses(), ImmutableList.of());
    assertEquals(copy.isRemotelyAccessible(), true);
}
 
Example 12
Source File: TestAtopSplit.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization()
{
    JsonCodec<AtopSplit> codec = JsonCodec.jsonCodec(AtopSplit.class);
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("+01:23"));
    AtopSplit split = new AtopSplit(HostAddress.fromParts("localhost", 123), now.toEpochSecond(), now.getZone());
    AtopSplit decoded = codec.fromJson(codec.toJson(split));
    assertEquals(decoded.getHost(), split.getHost());
    assertEquals(decoded.getDate(), split.getDate());
    assertEquals(decoded.getEpochSeconds(), split.getEpochSeconds());
    assertEquals(decoded.getTimeZone(), split.getTimeZone());
}
 
Example 13
Source File: TestExampleSplit.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonRoundTrip()
{
    JsonCodec<ExampleSplit> codec = jsonCodec(ExampleSplit.class);
    String json = codec.toJson(split);
    ExampleSplit copy = codec.fromJson(json);
    assertEquals(copy.getUri(), split.getUri());

    assertEquals(copy.getAddresses(), ImmutableList.of(HostAddress.fromString("127.0.0.1")));
    assertEquals(copy.isRemotelyAccessible(), true);
}
 
Example 14
Source File: TestExampleTableHandle.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonRoundTrip()
{
    JsonCodec<ExampleTableHandle> codec = jsonCodec(ExampleTableHandle.class);
    String json = codec.toJson(tableHandle);
    ExampleTableHandle copy = codec.fromJson(json);
    assertEquals(copy, tableHandle);
}
 
Example 15
Source File: ExampleClient.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Map<String, Map<String, ExampleTable>> lookupSchemas(URI metadataUri, JsonCodec<Map<String, List<ExampleTable>>> catalogCodec)
        throws IOException
{
    URL result = metadataUri.toURL();
    String json = Resources.toString(result, UTF_8);
    Map<String, List<ExampleTable>> catalog = catalogCodec.fromJson(json);

    return ImmutableMap.copyOf(transformValues(catalog, resolveAndIndexTables(metadataUri)));
}
 
Example 16
Source File: TestPrometheusSplit.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonRoundTrip()
{
    JsonCodec<PrometheusSplit> codec = jsonCodec(PrometheusSplit.class);
    String json = codec.toJson(split);
    PrometheusSplit copy = codec.fromJson(json);
    assertEquals(copy.getUri(), split.getUri());

    assertEquals(copy.getAddresses(), ImmutableList.of(HostAddress.fromString("127.0.0.1")));
    assertEquals(copy.isRemotelyAccessible(), true);
}
 
Example 17
Source File: TestPrometheusTableHandle.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonRoundTrip()
{
    JsonCodec<PrometheusTableHandle> codec = jsonCodec(PrometheusTableHandle.class);
    String json = codec.toJson(tableHandle);
    PrometheusTableHandle copy = codec.fromJson(json);
    assertEquals(copy, tableHandle);
}
 
Example 18
Source File: PrometheusClient.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Supplier<Map<String, Object>> metricsSupplier(final JsonCodec<Map<String, Object>> metricsCodec, final URI metadataUri)
{
    return () -> {
        try {
            byte[] json = getHttpResponse(metadataUri).bytes();
            Map<String, Object> metrics = metricsCodec.fromJson(json);
            return metrics;
        }
        catch (IOException | URISyntaxException e) {
            throw new UncheckedIOException((IOException) e);
        }
    };
}
 
Example 19
Source File: MetadataUtil.java    From presto with Apache License 2.0 4 votes vote down vote up
public static <T> void assertJsonRoundTrip(JsonCodec<T> codec, T object)
{
    String json = codec.toJson(object);
    T copy = codec.fromJson(json);
    assertEquals(copy, object);
}
 
Example 20
Source File: MockPinotClient.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T doHttpActionWithHeadersJson(Request.Builder requestBuilder, Optional<String> requestBody, JsonCodec<T> codec)
{
    return codec.fromJson(response);
}