本文整理汇总了Java中org.embulk.spi.DataException类的典型用法代码示例。如果您正苦于以下问题:Java DataException类的具体用法?Java DataException怎么用?Java DataException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataException类属于org.embulk.spi包,在下文中一共展示了DataException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jsonColumn
import org.embulk.spi.DataException; //导入依赖的package包/类
@Override
public void jsonColumn(final Column inputColumn)
{
String name = inputColumn.getName();
if (! shouldCast(name)){
if (pageReader.isNull(inputColumn)) {
pageBuilder.setNull(inputColumn);
}
else {
pageBuilder.setJson(inputColumn, pageReader.getJson(inputColumn));
}
}
else {
final Column outputColumn = outputColumnMap.get(inputColumn.getName());
PageBuildable op = new PageBuildable() {
public void run() throws DataException {
columnCaster.setFromJson(outputColumn, pageReader.getJson(inputColumn));
}
};
withStopOnInvalidRecord(op, inputColumn, outputColumn);
}
}
示例2: withStopOnInvalidRecord
import org.embulk.spi.DataException; //导入依赖的package包/类
private void withStopOnInvalidRecord(final PageBuildable op,
final Column inputColumn, final Column outputColumn) throws DataException
{
if (pageReader.isNull(inputColumn)) {
pageBuilder.setNull(outputColumn);
}
else {
if (task.getStopOnInvalidRecord()) {
op.run();
}
else {
try {
op.run();
}
catch (final DataException ex) {
logger.warn(ex.getMessage());
pageBuilder.setNull(outputColumn);
}
}
}
}
示例3: asLong
import org.embulk.spi.DataException; //导入依赖的package包/类
public static long asLong(Value value) throws DataException
{
if (value.isBooleanValue()) {
return BooleanCast.asLong(value.asBooleanValue().getBoolean());
}
else if (value.isIntegerValue()) {
return value.asIntegerValue().asLong();
}
else if (value.isFloatValue()) {
return DoubleCast.asLong(value.asFloatValue().toDouble());
}
else if (value.isStringValue()) {
return StringCast.asLong(value.asStringValue().asString());
}
else {
return JsonCast.asLong(value);
}
}
示例4: asTimestamp
import org.embulk.spi.DataException; //导入依赖的package包/类
public static Timestamp asTimestamp(Value value, TimestampParser parser) throws DataException
{
if (value.isBooleanValue()) {
return BooleanCast.asTimestamp(value.asBooleanValue().getBoolean());
}
else if (value.isIntegerValue()) {
return LongCast.asTimestamp(value.asIntegerValue().asLong());
}
else if (value.isFloatValue()) {
return DoubleCast.asTimestamp(value.asFloatValue().toDouble());
}
else if (value.isStringValue()) {
return StringCast.asTimestamp(value.asStringValue().asString(), parser);
}
else {
return JsonCast.asTimestamp(value);
}
}
示例5: longColumn
import org.embulk.spi.DataException; //导入依赖的package包/类
@Override
public void longColumn(final Column inputColumn)
{
String name = inputColumn.getName();
if (! shouldCast(name)){
if (pageReader.isNull(inputColumn)) {
pageBuilder.setNull(inputColumn);
}
else {
pageBuilder.setLong(inputColumn, pageReader.getLong(inputColumn));
}
}
else {
final Column outputColumn = outputColumnMap.get(name);
PageBuildable op = new PageBuildable() {
public void run() throws DataException {
columnCaster.setFromLong(outputColumn, pageReader.getLong(inputColumn));
}
};
withStopOnInvalidRecord(op, inputColumn, outputColumn);
}
}
示例6: stopOnBrokenJson
import org.embulk.spi.DataException; //导入依赖的package包/类
@Test
public void stopOnBrokenJson()
throws Exception
{
SchemaConfig schema = schema(
column("_c0", BOOLEAN), column("_c1", LONG), column("_c2", DOUBLE),
column("_c3", STRING), column("_c4", TIMESTAMP), column("_c5", JSON));
ConfigSource config = this.config.deepCopy().set("columns", schema).
set("stop_on_invalid_record", true);
try {
transaction(config, fileInput("BROKEN"));
fail();
}
catch (Throwable t) {
assertTrue(t instanceof DataException);
}
}
示例7: invalidBooleanString
import org.embulk.spi.DataException; //导入依赖的package包/类
@Test
public void invalidBooleanString()
throws Exception
{
SchemaConfig schema = schema(column("_c1", BOOLEAN));
ConfigSource config = this.config.deepCopy().set("columns", schema).
set("stop_on_invalid_record", true);
try {
transaction(config,
fileInput("[{\"_c1\" : \"INVALID\"}]"));
fail();
}
catch (Throwable t) {
assertTrue(t instanceof DataException);
}
}
示例8: stopOnBrokenColumn
import org.embulk.spi.DataException; //导入依赖的package包/类
@Test
public void stopOnBrokenColumn()
throws Exception
{
SchemaConfig schema = schema(column("_c1", TIMESTAMP));
ConfigSource config = this.config.deepCopy().set("columns", schema).
set("stop_on_invalid_record", true);
try {
transaction(config, fileInput("{\"_c1\" : \"INVALID\"}"));
fail();
}
catch (Throwable t) {
assertTrue(t instanceof DataException);
}
}
示例9: throwDataException
import org.embulk.spi.DataException; //导入依赖的package包/类
@Test
public void throwDataException()
throws Exception
{
SchemaConfig schema = schema(
column("_c0", BOOLEAN), column("_c1", LONG), column("_c2", DOUBLE),
column("_c3", STRING), column("_c4", TIMESTAMP), column("_c5", JSON));
ConfigSource config = this.config.deepCopy().set("columns", schema).
set("stop_on_invalid_record", true);
try {
transaction(config, fileInput(
"\"not_map_value\""
));
fail();
}
catch (Throwable t) {
assertTrue(t instanceof DataException);
}
}
示例10: stringColumn
import org.embulk.spi.DataException; //导入依赖的package包/类
@Override
public void stringColumn(final Column inputColumn)
{
String name = inputColumn.getName();
if (! shouldCast(name)){
if (pageReader.isNull(inputColumn)) {
pageBuilder.setNull(inputColumn);
}
else {
pageBuilder.setString(inputColumn, pageReader.getString(inputColumn));
}
}
else {
final Column outputColumn = outputColumnMap.get(inputColumn.getName());
PageBuildable op = new PageBuildable() {
public void run() throws DataException {
columnCaster.setFromString(outputColumn, pageReader.getString(inputColumn));
}
};
withStopOnInvalidRecord(op, inputColumn, outputColumn);
}
}
示例11: withStopOnInvalidRecord
import org.embulk.spi.DataException; //导入依赖的package包/类
private void withStopOnInvalidRecord(final PageBuildable op, final Column inputColumn, final Column outputColumn)
throws DataException
{
if (pageReader.isNull(inputColumn)) {
pageBuilder.setNull(outputColumn);
}
else {
if (task.getStopOnInvalidRecord()) {
op.run();
}
else {
try {
op.run();
}
catch (final DataException ex) {
logger.warn(ex.getMessage());
pageBuilder.setNull(outputColumn);
}
}
}
}
示例12: booleanColumn
import org.embulk.spi.DataException; //导入依赖的package包/类
@Override
public void booleanColumn(Column column)
{
if (value == null) {
pageBuilder.setNull(column);
} else {
throw new DataException(String.format("cannot convert value from %s", column.getType()));
}
}
示例13: longColumn
import org.embulk.spi.DataException; //导入依赖的package包/类
@Override
public void longColumn(Column column)
{
if (value == null) {
pageBuilder.setNull(column);
} else {
throw new DataException(String.format("cannot convert value from %s", column.getType()));
}
}
示例14: doubleColumn
import org.embulk.spi.DataException; //导入依赖的package包/类
@Override
public void doubleColumn(Column column)
{
if (value == null) {
pageBuilder.setNull(column);
} else {
throw new DataException(String.format("cannot convert value from %s", column.getType()));
}
}
示例15: asTimestamp
import org.embulk.spi.DataException; //导入依赖的package包/类
@Test
public void asTimestamp()
{
Timestamp expected = Timestamp.ofEpochSecond(1463084053, 123456000);
TimestampParser parser = new TimestampParser("%Y-%m-%d %H:%M:%S.%N", DateTimeZone.UTC);
assertEquals(expected, StringCast.asTimestamp("2016-05-12 20:14:13.123456", parser));
try {
StringCast.asTimestamp("foo", parser);
fail();
}
catch (Throwable t) {
assertTrue(t instanceof DataException);
}
}