Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for composite types in CLI's JSON output format #4589

Open
findepi opened this issue Jul 26, 2020 · 3 comments
Open

Add support for composite types in CLI's JSON output format #4589

findepi opened this issue Jul 26, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@findepi
Copy link
Member

findepi commented Jul 26, 2020

Currently formatting rows or maps fails:

Error running command: No ObjectCodec defined for the generator, can only serialize simple wrapper types (type passed java.util.LinkedHashMap)
java.lang.IllegalStateException: No ObjectCodec defined for the generator, can only serialize simple wrapper types (type passed java.util.LinkedHashMap)
	at com.fasterxml.jackson.core.JsonGenerator._writeSimpleObject(JsonGenerator.java:2168)
	at com.fasterxml.jackson.core.base.GeneratorBase.writeObject(GeneratorBase.java:391)
	at com.fasterxml.jackson.core.JsonGenerator.writeObjectField(JsonGenerator.java:1769)
	at io.prestosql.cli.JsonPrinter.printRows(JsonPrinter.java:49)
@findepi findepi added the enhancement New feature or request label Jul 26, 2020
@sweet-mentat
Copy link

Has this been addressed? I am getting this error:
Error running command: No ObjectCodec defined for the generator, can only serialize simple wrapper types (type passed java.util.ArrayList)
Does the CLI JSON output format only support simple data types?

@njpeterman
Copy link

There's too much red tape for me to PR this myself, but I was able to get this working locally with some minor changes.

Specifically, in the JsonPrinter, the printRows method needs to configure an object mapper for the json generator:

         ...
         JsonFactory jsonFactory = new JsonFactory();
         for (List<?> row : rows) {
             JsonGenerator jsonGenerator = jsonFactory.createGenerator(writer);
+            jsonGenerator.setCodec(new ObjectMapper());
             jsonGenerator.writeStartObject();
             ...

And then in order to access the object mapper, the trino-cli module needs to declare jackson-databind as a dependency in its pom.xml:

<dependency>
     <groupId>com.fasterxml.jackson.core</groupId>
     <artifactId>jackson-databind</artifactId>
</dependency>

Hope this helps!

@hackeryang
Copy link
Member

There's too much red tape for me to PR this myself, but I was able to get this working locally with some minor changes.

Specifically, in the JsonPrinter, the printRows method needs to configure an object mapper for the json generator:

         ...
         JsonFactory jsonFactory = new JsonFactory();
         for (List<?> row : rows) {
             JsonGenerator jsonGenerator = jsonFactory.createGenerator(writer);
+            jsonGenerator.setCodec(new ObjectMapper());
             jsonGenerator.writeStartObject();
             ...

And then in order to access the object mapper, the trino-cli module needs to declare jackson-databind as a dependency in its pom.xml:

<dependency>
     <groupId>com.fasterxml.jackson.core</groupId>
     <artifactId>jackson-databind</artifactId>
</dependency>

Hope this helps!

Thank you for your advice, we encountered a similar problem too, there was some complex row and map column types in our hive table:
image
After we modified some source codes just as what you suggested, the error is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

4 participants