Skip to content

Commit

Permalink
Merge pull request #6 from embulk/use-JsonValue
Browse files Browse the repository at this point in the history
Use org.embulk.spi.json.JsonValue, instead of org.msgpack.value.Value
  • Loading branch information
dmikurube authored Sep 25, 2023
2 parents a8636bc + 204e5fe commit 8614f0b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ dependencies {
implementation "org.embulk:embulk-util-csv:0.2.3"
implementation "org.embulk:embulk-util-config:0.3.4"
implementation "org.embulk:embulk-util-file:0.1.5"
implementation "org.embulk:embulk-util-json:0.2.2"
implementation "org.embulk:embulk-util-json:0.3.0"
implementation "org.embulk:embulk-util-text:0.1.3"
implementation "org.embulk:embulk-util-timestamp:0.2.2"

testImplementation "junit:junit:4.13.2"
testImplementation "org.embulk:embulk-spi:0.10.50"
testImplementation "org.embulk:embulk-core:0.10.50"
testImplementation "org.embulk:embulk-deps:0.10.50"
testImplementation "org.embulk:embulk-junit4:0.10.50"
testImplementation "org.embulk:embulk-spi:0.11"
testImplementation "org.embulk:embulk-core:0.11.0"
testImplementation "org.embulk:embulk-deps:0.11.0"
testImplementation "org.embulk:embulk-junit4:0.11.0"
testImplementation "com.google.guava:guava:18.0"

testImplementation "org.embulk:embulk-formatter-csv:0.10.42"
Expand Down
2 changes: 1 addition & 1 deletion gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ org.embulk:embulk-spi:0.11=compileClasspath
org.embulk:embulk-util-config:0.3.4=compileClasspath,runtimeClasspath
org.embulk:embulk-util-csv:0.2.3=compileClasspath,runtimeClasspath
org.embulk:embulk-util-file:0.1.5=compileClasspath,runtimeClasspath
org.embulk:embulk-util-json:0.2.2=compileClasspath,runtimeClasspath
org.embulk:embulk-util-json:0.3.0=compileClasspath,runtimeClasspath
org.embulk:embulk-util-rubytime:0.3.3=compileClasspath,runtimeClasspath
org.embulk:embulk-util-text:0.1.3=compileClasspath,runtimeClasspath
org.embulk:embulk-util-timestamp:0.2.2=compileClasspath,runtimeClasspath
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/embulk/parser/csv/CsvParserPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
import java.io.IOException;
import java.nio.charset.Charset;
import java.time.Instant;
import java.time.format.DateTimeParseException;
Expand Down Expand Up @@ -52,7 +53,7 @@
import org.embulk.util.csv.InvalidCsvFormatException;
import org.embulk.util.csv.RecordHasUnexpectedTrailingColumnException;
import org.embulk.util.json.JsonParseException;
import org.embulk.util.json.JsonParser;
import org.embulk.util.json.JsonValueParser;
import org.embulk.util.text.LineDecoder;
import org.embulk.util.text.LineDelimiter;
import org.embulk.util.text.Newline;
Expand Down Expand Up @@ -316,7 +317,7 @@ public void run(TaskSource taskSource, final Schema schema,
FileInput input, PageOutput output) {
final PluginTask task = CONFIG_MAPPER_FACTORY.createTaskMapper().map(taskSource, PluginTask.class);
final TimestampFormatter[] timestampFormatters = newTimestampColumnFormatters(task, task.getSchemaConfig());
final JsonParser jsonParser = new JsonParser();
final JsonValueParser.Builder jsonParserBuilder = JsonValueParser.builder();
final CsvTokenizer.Builder tokenizerBuilder = buildCsvTokenizerBuilder(task);
final boolean allowOptionalColumns = task.getAllowOptionalColumns();
final boolean allowExtraColumns = task.getAllowExtraColumns();
Expand Down Expand Up @@ -419,8 +420,11 @@ public void jsonColumn(Column column) {
pageBuilder.setNull(column);
} else {
try {
pageBuilder.setJson(column, jsonParser.parse(v));
} catch (JsonParseException e) {
pageBuilder.setJson(column, jsonParserBuilder.build(v).readJsonValue());
} catch (final JsonParseException e) {
// TODO support default value
throw new CsvRecordValidateException(e);
} catch (final IOException e) {
// TODO support default value
throw new CsvRecordValidateException(e);
}
Expand Down

0 comments on commit 8614f0b

Please sign in to comment.