org.embulk.config.ConfigException Java Examples

The following examples show how to use org.embulk.config.ConfigException. 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: JsonPathUtil.java    From embulk-filter-column with MIT License 6 votes vote down vote up
public static void assertSupportedPathToken(PathToken pathToken, String path)
{
    if (pathToken instanceof ArrayPathToken) {
        ArrayIndexOperation arrayIndexOperation = ((ArrayPathToken) pathToken).getArrayIndexOperation();
        assertSupportedArrayPathToken(arrayIndexOperation, path);
    }
    else if (pathToken instanceof ScanPathToken) {
        throw new ConfigException(String.format("scan path token is not supported \"%s\"", path));
    }
    else if (pathToken instanceof FunctionPathToken) {
        throw new ConfigException(String.format("function path token is not supported \"%s\"", path));
    }
    else if (pathToken instanceof PredicatePathToken) {
        throw new ConfigException(String.format("predicate path token is not supported \"%s\"", path));
    }
}
 
Example #2
Source File: JsonPathUtil.java    From embulk-filter-column with MIT License 6 votes vote down vote up
public static void assertJsonPathFormat(String path)
{
    Path compiledPath;
    try {
        compiledPath = PathCompiler.compile(path);
    }
    catch (InvalidPathException e) {
        throw new ConfigException(String.format("jsonpath %s, %s", path, e.getMessage()));
    }
    PathToken pathToken = compiledPath.getRoot();
    while (true) {
        assertSupportedPathToken(pathToken, path);
        if (pathToken.isLeaf()) {
            break;
        }
        pathToken = pathToken.next();
    }
}
 
Example #3
Source File: JsonlParserPlugin.java    From embulk-parser-jsonl with MIT License 6 votes vote down vote up
private SchemaConfig getSchemaConfig(PluginTask task)
{
    if (task.getOldSchemaConfig().isPresent()) {
        log.warn("Please use 'columns' option instead of 'schema' because the 'schema' option is deprecated. The next version will stop 'schema' option support.");
    }

    if (task.getSchemaConfig().isPresent()) {
        return task.getSchemaConfig().get();
    }
    else if (task.getOldSchemaConfig().isPresent()) {
        return task.getOldSchemaConfig().get();
    }
    else {
        throw new ConfigException("Attribute 'columns' is required but not set");
    }
}
 
Example #4
Source File: JsonColumn.java    From embulk-filter-column with MIT License 6 votes vote down vote up
public static Long getTailIndex(String path)
{
    Path compiledPath = PathCompiler.compile(path);
    PathToken tail = ((RootPathToken) compiledPath.getRoot()).getTail();
    if (tail instanceof ArrayPathToken) {
        ArrayIndexOperation arrayIndexOperation = ((ArrayPathToken) tail).getArrayIndexOperation();
        if (arrayIndexOperation == null) {
            throw new ConfigException(String.format("Array Slice Operation is not supported \"%s\"", path));
        }
        if (arrayIndexOperation.isSingleIndexOperation()) {
            return arrayIndexOperation.indexes().get(0).longValue();
        }
        else {
            throw new ConfigException(String.format("Multi Array Indexes is not supported \"%s\"", path));
        }
    }
    else {
        return null;
    }
}
 
Example #5
Source File: S3FileOutputPlugin.java    From embulk-output-s3 with MIT License 5 votes vote down vote up
private void validateSequenceFormat(PluginTask task)
{
    try {
        @SuppressWarnings("unused")
        String dontCare = String.format(Locale.ENGLISH,
                task.getSequenceFormat(), 0, 0);
    }
    catch (IllegalFormatException ex) {
        throw new ConfigException(
                "Invalid sequence_format: parameter for file output plugin",
                ex);
    }
}
 
Example #6
Source File: ParquetOutputPluginTest.java    From embulk-output-parquet with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void checkColumnsRequired()
{
    ConfigSource config = Exec.newConfigSource();

    config.loadConfig(ParquetOutputPlugin.PluginTask.class);
}
 
Example #7
Source File: TestColumnFilterPlugin.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void configure_EitherOfColumnsOrDropColumnsCanBeSpecified()
{
    ConfigSource config = configFromYamlString(
            "type: column",
            "columns:",
            "- {name: a}",
            "drop_columns:",
            "- {name: a}");
    Schema inputSchema = schema(
            new Column(0, "a", STRING),
            new Column(1, "b", STRING));

    transaction(config, inputSchema);
}
 
Example #8
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void configException_MArraySliceOperationAtMiddlePosition()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "columns:",
            "- name: \"$.json1[1:2].key1\"");
    Schema inputSchema = Schema.builder()
            .add("json1", JSON)
            .build();
    jsonVisitor(task, inputSchema);
}
 
Example #9
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void configException_ArraySliceOperation()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "columns:",
            "- name: \"$.json1[1:2]\"");
    Schema inputSchema = Schema.builder()
            .add("json1", JSON)
            .build();
    jsonVisitor(task, inputSchema);
}
 
Example #10
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void configException_IndexOperationAtMiddlePosition()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "columns:",
            "- name: \"$.json1[0,1].key1\"");
    Schema inputSchema = Schema.builder()
            .add("json1", JSON)
            .build();
    jsonVisitor(task, inputSchema);
}
 
Example #11
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void configException_MultiIndexOperation()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "columns:",
            "- name: \"$.json1[0,1]\"");
    Schema inputSchema = Schema.builder()
            .add("json1", JSON)
            .build();
    jsonVisitor(task, inputSchema);
}
 
Example #12
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void configException_ScanPathToken()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "columns:",
            "- name: \"$.json1..key1\"");
    Schema inputSchema = Schema.builder()
            .add("json1", JSON)
            .build();
    jsonVisitor(task, inputSchema);
}
 
Example #13
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void configException_PredicatePathToken()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "columns:",
            "- name: \"$.store.book[?(@.price < 10)]\"");
    Schema inputSchema = Schema.builder()
            .add("store", JSON)
            .build();
    jsonVisitor(task, inputSchema);
}
 
Example #14
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void configException_FunctionPathToken()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "columns:",
            "- name: \"$['json1'].length()\"");
    Schema inputSchema = Schema.builder()
            .add("json1", JSON)
            .build();
    jsonVisitor(task, inputSchema);
}
 
Example #15
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void configException_PropertyIsNotSeparatedByCommas()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "columns:",
            " - name: \"$['json1'}['k1']\"");
    Schema inputSchema = Schema.builder()
            .add("json1", JSON)
            .build();
    jsonVisitor(task, inputSchema);
}
 
Example #16
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void configException_MultiProperties()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "columns:",
            "- name: \"$['json1','k1']\"");
    Schema inputSchema = Schema.builder()
            .add("json1", JSON)
            .build();
    jsonVisitor(task, inputSchema);
}
 
Example #17
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void assertDoNotEndsWithArrayWildcard_Columns()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "columns:",
            "  - {name: \"$.json1.b.b[*]\"}");
    Schema inputSchema = Schema.builder().build();
    // b[*] should be written as b
    jsonVisitor(task, inputSchema);
}
 
Example #18
Source File: TestJsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
@Test(expected = ConfigException.class)
public void assertDoNotEndsWithArrayWildcard_AddColumns()
{
    PluginTask task = taskFromYamlString(
            "type: column",
            "add_columns:",
            "  - {name: \"$.json1.b.b[*]\", type: json, default: []}");
    Schema inputSchema = Schema.builder().build();
    // b[*] should be written as b
    jsonVisitor(task, inputSchema);
}
 
Example #19
Source File: JsonColumn.java    From embulk-filter-column with MIT License 5 votes vote down vote up
private String getTailName(RootPathToken root)
{
    PathToken pathToken = root.getTail();
    if (pathToken instanceof PropertyPathToken) {
        if (!((PropertyPathToken) pathToken).singlePropertyCase()) {
            throw new ConfigException(String.format("Multiple property is not supported \"%s\"", root.toString()));
        }
        return ((PropertyPathToken) pathToken).getProperties().get(0);
    }
    else {
        return null;
    }
}
 
Example #20
Source File: JsonColumn.java    From embulk-filter-column with MIT License 5 votes vote down vote up
public JsonColumn(String path, Type type, Value defaultValue, String src)
{
    Path compiledPath = PathCompiler.compile(path);
    Path compiledSrc = src == null ? compiledPath : PathCompiler.compile(src);
    RootPathToken compiledRoot = (RootPathToken) compiledPath.getRoot();
    RootPathToken compiledSrcRoot = (RootPathToken) compiledSrc.getRoot();
    this.path = compiledPath.toString();
    this.type = type;
    this.defaultValue = (defaultValue == null ? ValueFactory.newNil() : defaultValue);
    this.src = compiledSrc.toString();

    this.pathValue = ValueFactory.newString(path);
    this.parentPath = compiledPath.getParentPath();

    this.tailIndex = getTailIndex(compiledRoot);
    this.parentPathValue = ValueFactory.newString(parentPath);
    String tailName = getTailName(compiledRoot);
    this.tailNameValue = tailName == null ? ValueFactory.newNil() : ValueFactory.newString(tailName);

    this.srcValue = ValueFactory.newString(this.src);
    this.srcParentPath = compiledSrc.getParentPath();
    this.srcTailIndex = getTailIndex(compiledSrcRoot);
    this.srcParentPathValue = ValueFactory.newString(this.srcParentPath);
    String srcTailName = getTailName(compiledSrcRoot);
    this.srcTailNameValue = srcTailName == null ? ValueFactory.newNil() : ValueFactory.newString(srcTailName);

    if (!srcParentPath.equals(parentPath)) {
        throw new ConfigException(String.format("The branch (parent path) of src \"%s\" must be same with of name \"%s\" yet", src, path));
    }
}
 
Example #21
Source File: JsonVisitor.java    From embulk-filter-column with MIT License 5 votes vote down vote up
static Value getDefault(PluginTask task, String name, Type type, ColumnConfig columnConfig)
{
    Object defaultValue = ColumnVisitorImpl.getDefault(task, name, type, columnConfig);
    if (defaultValue == null) {
        return ValueFactory.newNil();
    }
    if (type instanceof BooleanType) {
        return ValueFactory.newBoolean((Boolean) defaultValue);
    }
    else if (type instanceof LongType) {
        return ValueFactory.newInteger((Long) defaultValue);
    }
    else if (type instanceof DoubleType) {
        return ValueFactory.newFloat((Double) defaultValue);
    }
    else if (type instanceof StringType) {
        return ValueFactory.newString((String) defaultValue.toString());
    }
    else if (type instanceof JsonType) {
        return (Value) defaultValue;
    }
    else if (type instanceof TimestampType) {
        throw new ConfigException("type: timestamp is not available in json path");
    }
    else {
        throw new ConfigException(String.format("type: '%s' is not supported", type));
    }
}
 
Example #22
Source File: JsonPathUtil.java    From embulk-filter-column with MIT License 5 votes vote down vote up
public static void assertDoNotEndsWithArrayWildcard(String path)
{
    Path compiledPath;
    try {
        compiledPath = PathCompiler.compile(path);
    }
    catch (InvalidPathException e) {
        throw new ConfigException(String.format("jsonpath %s, %s", path, e.getMessage()));
    }
    if (((RootPathToken) compiledPath.getRoot()).getTailPath().equals("[*]")) {
        throw new ConfigException(String.format("%s wrongly ends with [*], perhaps you can remove the [*]", compiledPath.toString()));
    }
}
 
Example #23
Source File: JsonPathUtil.java    From embulk-filter-column with MIT License 5 votes vote down vote up
public static void assertSupportedArrayPathToken(ArrayIndexOperation arrayIndexOperation, String path)
{
    if (arrayIndexOperation == null) {
        throw new ConfigException(String.format("Array Slice Operation is not supported \"%s\"", path));
    }
    else if (!arrayIndexOperation.isSingleIndexOperation()) {
        throw new ConfigException(String.format("Multi Array Indexes is not supported \"%s\"", path));
    }
}
 
Example #24
Source File: ColumnFilterPlugin.java    From embulk-filter-column with MIT License 4 votes vote down vote up
private void configure(PluginTask task)
{
    if (task.getColumns().size() > 0 && task.getDropColumns().size() > 0) {
        throw new ConfigException("Either of \"columns\", \"drop_columns\" can be specified.");
    }
}