Skip to content

Commit

Permalink
Fail on trailing content in TPC-DS / TPC-H stats resource JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Jun 28, 2022
1 parent a4ebed3 commit 5f5b914
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;

Expand Down Expand Up @@ -89,6 +90,16 @@ public static <T> T parseJson(ObjectMapper mapper, InputStream inputStream, Clas
return parseJson(mapper, ObjectMapper::createParser, inputStream, javaType);
}

public static <T> T parseJson(URL url, Class<T> javaType)
{
return parseJson(OBJECT_MAPPER, url, javaType);
}

public static <T> T parseJson(ObjectMapper mapper, URL url, Class<T> javaType)
{
return parseJson(mapper, ObjectMapper::createParser, url, javaType);
}

private static <I, T> T parseJson(ObjectMapper mapper, ParserConstructor<I> parserConstructor, I input, Class<T> javaType)
{
requireNonNull(mapper, "mapper is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.nio.file.Paths;
import java.util.Optional;

import static io.trino.plugin.base.util.JsonUtils.parseJson;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;

Expand Down Expand Up @@ -83,7 +84,7 @@ private Optional<TableStatisticsData> readStatistics(String resourcePath)
return Optional.empty();
}
try {
return Optional.of(objectMapper.readValue(resource, TableStatisticsData.class));
return Optional.of(parseJson(objectMapper, resource, TableStatisticsData.class));
}
catch (Exception e) {
throw new RuntimeException(format("Failed to parse stats from resource [%s]", resourcePath), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static io.trino.plugin.base.util.JsonUtils.parseJson;
import static io.trino.plugin.tpch.util.Optionals.withBoth;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down Expand Up @@ -77,7 +78,7 @@ public Optional<TableStatisticsData> load(String schemaName, TpchTable<?> table,
return Optional.empty();
}
try {
return Optional.of(objectMapper.readValue(resource, TableStatisticsData.class));
return Optional.of(parseJson(objectMapper, resource, TableStatisticsData.class));
}
catch (Exception e) {
throw new RuntimeException(format("Failed to parse stats from resource [%s]", resourcePath), e);
Expand Down

0 comments on commit 5f5b914

Please sign in to comment.