Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ See [embulk-output-sqlserver](embulk-output-sqlserver/).
- **default_timezone**: If input column type (embulk type) is timestamp, this plugin needs to format the timestamp into a SQL string. This default_timezone option is used to control the timezone. You can overwrite timezone for each columns using column_options option. (string, default: `UTC`)
- **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
- **type**: type of a column when this plugin creates new tables (e.g. `VARCHAR(255)`, `INTEGER NOT NULL UNIQUE`). This used when this plugin creates intermediate tables (insert and truncate_insert modes), when it creates the target table (replace mode), and when it creates nonexistent target table automatically. (string, default: depends on input column type. `BIGINT` if input column type is long, `BOOLEAN` if boolean, `DOUBLE PRECISION` if double, `CLOB` if string, `TIMESTAMP` if timestamp)
- **value_type**: This plugin converts input column type (embulk type) into a database type to build a INSERT statement. This value_type option controls the type of the value in a INSERT statement. (string, default: depends on input column type. Available values options are: `byte`, `short`, `int`, `long`, `double`, `float`, `boolean`, `string`, `nstring`, `date`, `time`, `timestamp`, `decimal`, `null`, `pass`)
- **value_type**: This plugin converts input column type (embulk type) into a database type to build a INSERT statement. This value_type option controls the type of the value in a INSERT statement. (string, default: depends on the sql type of the column. Available values options are: `byte`, `short`, `int`, `long`, `double`, `float`, `boolean`, `string`, `nstring`, `date`, `time`, `timestamp`, `decimal`, `json`, `null`, `pass`)
- **timestamp_format**: If input column type (embulk type) is timestamp and value_type is `string` or `nstring`, this plugin needs to format the timestamp value into a string. This timestamp_format option is used to control the format of the timestamp. (string, default: `%Y-%m-%d %H:%M:%S.%6N`)
- **timezone**: If input column type (embulk type) is timestamp, this plugin needs to format the timestamp value into a SQL string. In this cases, this timezone option is used to control the timezone. (string, value of default_timezone option is used by default)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.math.BigDecimal;
import java.io.IOException;
import java.sql.SQLException;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class BigDecimalColumnSetter
extends ColumnSetter
Expand Down Expand Up @@ -65,4 +67,10 @@ public void timestampValue(Timestamp v) throws IOException, SQLException
{
defaultValue.setBigDecimal();
}

@Override
public void jsonValue(Value v) throws IOException, SQLException
{
defaultValue.setBigDecimal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.IOException;
import java.sql.SQLException;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class BooleanColumnSetter
extends ColumnSetter
Expand Down Expand Up @@ -50,4 +52,10 @@ public void timestampValue(Timestamp v) throws IOException, SQLException
{
defaultValue.setBoolean();
}

@Override
public void jsonValue(Value v) throws IOException, SQLException
{
defaultValue.setBoolean();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import java.io.IOException;
import java.sql.SQLException;
import java.math.RoundingMode;

import com.google.common.math.DoubleMath;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class ByteColumnSetter
extends ColumnSetter
Expand Down Expand Up @@ -72,4 +75,10 @@ public void timestampValue(Timestamp v) throws IOException, SQLException
{
defaultValue.setByte();
}

@Override
public void jsonValue(Value v) throws IOException, SQLException
{
defaultValue.setByte();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.IOException;
import java.sql.SQLException;
import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;

import org.embulk.output.jdbc.BatchInsert;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.spi.time.Timestamp;
import org.msgpack.value.Value;

public abstract class ColumnSetter
{
Expand Down Expand Up @@ -41,4 +43,6 @@ public int getSqlType()
public abstract void stringValue(String v) throws IOException, SQLException;

public abstract void timestampValue(Timestamp v) throws IOException, SQLException;

public abstract void jsonValue(Value v) throws IOException, SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public ColumnSetter newColumnSetter(JdbcColumn column, JdbcColumnOption option)
return new SqlTimestampColumnSetter(batch, column, newDefaultValueSetter(column, option), newCalendar(option));
case "decimal":
return new BigDecimalColumnSetter(batch, column, newDefaultValueSetter(column, option));
case "json":
return new JsonColumnSetter(batch, column, newDefaultValueSetter(column, option));
case "null":
return new NullColumnSetter(batch, column, newDefaultValueSetter(column, option));
case "pass":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,18 @@ public void stringColumn(Column column)
}

@Override
public void jsonColumn(Column column) {
throw new UnsupportedOperationException("This plugin doesn't support json type. Please try to upgrade version of the plugin using 'embulk gem update' command. If the latest version still doesn't support json type, please contact plugin developers, or change configuration of input plugin not to use json type.");
public void jsonColumn(Column column)
{
try {
if (pageReader.isNull(column)) {
setter.nullValue();
} else {
setter.jsonValue(pageReader.getJson(column));
}
} catch (IOException | SQLException ex) {
// TODO exception class
throw new RuntimeException(ex);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ public DefaultValueSetter(BatchInsert batch, JdbcColumn column)
public abstract void setSqlTime() throws IOException, SQLException;

public abstract void setSqlTimestamp() throws IOException, SQLException;

public abstract void setJson() throws IOException, SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.IOException;
import java.sql.SQLException;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class DoubleColumnSetter
extends ColumnSetter
Expand Down Expand Up @@ -57,4 +59,10 @@ public void timestampValue(Timestamp v) throws IOException, SQLException
{
defaultValue.setDouble();
}

@Override
public void jsonValue(Value v) throws IOException, SQLException
{
defaultValue.setDouble();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.IOException;
import java.sql.SQLException;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class FloatColumnSetter
extends ColumnSetter
Expand Down Expand Up @@ -57,4 +59,10 @@ public void timestampValue(Timestamp v) throws IOException, SQLException
{
defaultValue.setFloat();
}

@Override
public void jsonValue(Value v) throws IOException, SQLException
{
defaultValue.setFloat();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import java.io.IOException;
import java.sql.SQLException;
import java.math.RoundingMode;

import com.google.common.math.DoubleMath;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class IntColumnSetter
extends ColumnSetter
Expand Down Expand Up @@ -72,4 +75,10 @@ public void timestampValue(Timestamp v) throws IOException, SQLException
{
defaultValue.setInt();
}

@Override
public void jsonValue(Value v) throws IOException, SQLException
{
defaultValue.setInt();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.embulk.output.jdbc.setter;

import java.io.IOException;
import java.sql.SQLException;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class JsonColumnSetter
extends ColumnSetter
{
public JsonColumnSetter(BatchInsert batch, JdbcColumn column,
DefaultValueSetter defaultValue)
{
super(batch, column, defaultValue);
}

@Override
public void nullValue() throws IOException, SQLException
{
defaultValue.setJson();
}

@Override
public void booleanValue(boolean v) throws IOException, SQLException
{
defaultValue.setJson();
}

@Override
public void longValue(long v) throws IOException, SQLException
{
defaultValue.setJson();
}

@Override
public void doubleValue(double v) throws IOException, SQLException
{
defaultValue.setJson();
}

@Override
public void stringValue(String v) throws IOException, SQLException
{
defaultValue.setJson();
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
{
defaultValue.setJson();
}

@Override
public void jsonValue(Value v) throws IOException, SQLException {
batch.setString(v.toJson());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import java.io.IOException;
import java.sql.SQLException;
import java.math.RoundingMode;

import com.google.common.math.DoubleMath;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class LongColumnSetter
extends ColumnSetter
Expand Down Expand Up @@ -68,4 +71,10 @@ public void timestampValue(Timestamp v) throws IOException, SQLException
{
defaultValue.setLong();
}

@Override
public void jsonValue(Value v) throws IOException, SQLException
{
defaultValue.setLong();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import java.io.IOException;
import java.sql.SQLException;

import org.embulk.spi.time.Timestamp;
import org.embulk.spi.time.TimestampFormatter;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class NStringColumnSetter
extends ColumnSetter
Expand Down Expand Up @@ -55,4 +57,10 @@ public void timestampValue(Timestamp v) throws IOException, SQLException
{
batch.setNString(timestampFormatter.format(v));
}

@Override
public void jsonValue(Value v) throws IOException, SQLException
{
defaultValue.setNString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.IOException;
import java.sql.SQLException;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class NullColumnSetter
extends ColumnSetter
Expand Down Expand Up @@ -50,4 +52,10 @@ public void nullValue() throws IOException, SQLException
{
defaultValue.setNull();
}

@Override
public void jsonValue(Value v) throws IOException, SQLException
{
defaultValue.setNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ public void setSqlTimestamp() throws IOException, SQLException
{
batch.setNull(column.getSqlType());
}

@Override
public void setJson() throws IOException, SQLException
{
batch.setNull(column.getSqlType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.util.Calendar;
import java.io.IOException;
import java.sql.SQLException;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;

public class PassThroughColumnSetter
extends ColumnSetter
Expand Down Expand Up @@ -55,4 +57,10 @@ public void timestampValue(Timestamp v) throws IOException, SQLException
{
batch.setSqlTimestamp(v, calendar);
}

@Override
public void jsonValue(Value v) throws IOException, SQLException
{
batch.setString(v.toJson());
}
}
Loading