-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#16] feat(schema) add JSON serialize and deserialize support for sch…
…ema (#20) ### What changes were proposed in this pull request? This PR adds JSON serde support for schema system. ### Why are the changes needed? The adds of JSON serde support will help to support REST API for Unified Catalog. Fix: #16 ### Does this PR introduce _any_ user-facing change? NA ### How was this patch tested? And new UTs.
- Loading branch information
Showing
13 changed files
with
582 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
core/src/main/java/com/datastrato/unified_catalog/schema/SchemaVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
core/src/main/java/com/datastrato/unified_catalog/schema/hasExtraInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
core/src/main/java/com/datastrato/unified_catalog/schema/json/JsonUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.datastrato.unified_catalog.schema.json; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import io.substrait.type.StringTypeVisitor; | ||
import io.substrait.type.Type; | ||
import io.substrait.type.parser.ParseToPojo; | ||
import io.substrait.type.parser.TypeStringParser; | ||
import java.io.IOException; | ||
|
||
public class JsonUtils { | ||
private static ObjectMapper mapper = null; | ||
|
||
public static ObjectMapper objectMapper() { | ||
if (mapper == null) { | ||
synchronized (JsonUtils.class) { | ||
if (mapper == null) { | ||
mapper = | ||
new ObjectMapper() | ||
.registerModule(new JavaTimeModule()) | ||
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); | ||
} | ||
} | ||
} | ||
|
||
return mapper; | ||
} | ||
|
||
public static class TypeSerializer extends JsonSerializer<io.substrait.type.Type> { | ||
private final StringTypeVisitor visitor = new StringTypeVisitor(); | ||
|
||
@Override | ||
public void serialize(Type value, JsonGenerator gen, SerializerProvider serializers) | ||
throws IOException { | ||
try { | ||
gen.writeString(value.accept(visitor)); | ||
} catch (Exception e) { | ||
throw new IOException("Unable to serialize type " + value, e); | ||
} | ||
} | ||
} | ||
|
||
public static class TypeDeserializer extends JsonDeserializer<io.substrait.type.Type> { | ||
|
||
@Override | ||
public Type deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
String s = p.getValueAsString(); | ||
try { | ||
return TypeStringParser.parse(s, ParseToPojo::type); | ||
} catch (Exception e) { | ||
throw new IOException("Unable to parse string " + s.replace("\n", " \\n"), e); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.