本文整理汇总了Java中org.embulk.spi.time.TimestampParser类的典型用法代码示例。如果您正苦于以下问题:Java TimestampParser类的具体用法?Java TimestampParser怎么用?Java TimestampParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TimestampParser类属于org.embulk.spi.time包,在下文中一共展示了TimestampParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: asTimestamp
import org.embulk.spi.time.TimestampParser; //导入依赖的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);
}
}
示例2: initializeExpandedColumns
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
private List<ExpandedColumn> initializeExpandedColumns(PluginTask task,
Schema outputSchema)
{
ImmutableList.Builder<ExpandedColumn> expandedJsonColumnsBuilder = ImmutableList.builder();
for (Column outputColumn : outputSchema.getColumns()) {
for (ColumnConfig expandedColumnConfig : task.getExpandedColumns()) {
if (outputColumn.getName().equals(expandedColumnConfig.getName())) {
TimestampParser timestampParser = null;
if (Types.TIMESTAMP.equals(expandedColumnConfig.getType())) {
timestampParser = createTimestampParser(task, expandedColumnConfig);
}
ExpandedColumn expandedColumn = new ExpandedColumn(outputColumn.getName(),
outputColumn,
task.getRoot() + outputColumn.getName(),
Optional.fromNullable(timestampParser));
expandedJsonColumnsBuilder.add(expandedColumn);
}
}
}
return expandedJsonColumnsBuilder.build();
}
示例3: JoinFilePageOutput
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
JoinFilePageOutput(
Schema inputSchema,
Schema outputSchema,
Column joinBaseColumn,
HashMap<String, HashMap<String, String>> table,
List<Column> joinColumns,
HashMap<String, TimestampParser> timestampParserMap,
PageOutput pageOutput
)
{
this.pageReader = new PageReader(inputSchema);
this.pageBuilder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, pageOutput);
this.joinBaseColumn = joinBaseColumn;
this.table = table;
this.joinColumns = joinColumns;
this.timestampParserMap = timestampParserMap;
}
示例4: buildTimestampParserMap
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
private HashMap<String, TimestampParser> buildTimestampParserMap(ScriptingContainer jruby, List<ColumnConfig> columns, String joinedColumnPrefix, String timeZone)
{
final HashMap<String, TimestampParser> timestampParserMap = Maps.newHashMap();
for (ColumnConfig columnConfig: columns) {
if (Types.TIMESTAMP.equals(columnConfig.getType())) {
String format = columnConfig.getOption().get(String.class, "format");
DateTimeZone timezone = DateTimeZone.forID(timeZone);
TimestampParser parser = new TimestampParser(jruby, format, timezone);
String columnName = joinedColumnPrefix + columnConfig.getName();
timestampParserMap.put(columnName, parser);
}
}
return timestampParserMap;
}
示例5: timestampColumn
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
@Override
public void timestampColumn(Column column) {
if (this.value == null) {
pageBuilder.setNull(column);
}
else {
TimestampParser parser = timestampParsers[column.getIndex()];
pageBuilder.setTimestamp(column, parser.parse(value));
}
}
示例6: asTimestamp
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
public static Timestamp asTimestamp(String value, TimestampParser parser) throws DataException
{
try {
return parser.parse(value);
}
catch (TimestampParseException ex) {
throw new DataException(buildErrorMessage("timestamp", value), ex);
}
}
示例7: ColumnVisitorImpl
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
public ColumnVisitorImpl(PluginTask task, Schema schema, PageBuilder pageBuilder, TimestampParser[] timestampParsers)
{
this.task = task;
this.schema = schema;
this.pageBuilder = pageBuilder;
this.timestampParsers = timestampParsers.clone();
this.autoTypecasts = new Boolean[schema.size()];
buildAutoTypecasts();
}
示例8: asTimestamp
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
@Test
public void asTimestamp()
{
Timestamp expected = Timestamp.ofEpochSecond(1463084053, 123456000);
TimestampParser parser = new TimestampParser(jruby, "%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);
}
}
示例9: createResource
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
@Before
public void createResource()
{
jruby = new ScriptingContainer();
thrown = new DataException("any");
Value[] kvs = new Value[2];
kvs[0] = ValueFactory.newString("k");
kvs[1] = ValueFactory.newString("v");
mapValue = ValueFactory.newMap(kvs);
parser = new TimestampParser(jruby, "%Y-%m-%d %H:%M:%S.%N", DateTimeZone.UTC);
}
示例10: buildTimestampParserMap
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
private void buildTimestampParserMap()
{
// columnName => TimestampParser
for (ColumnConfig columnConfig : task.getColumns()) {
if (PathCompiler.isProbablyJsonPath(columnConfig.getName())) {
continue; // type: json columns do not support type: timestamp
}
Column inputColumn = inputSchema.lookupColumn(columnConfig.getName());
if (inputColumn.getType() instanceof StringType && columnConfig.getType() instanceof TimestampType) {
TimestampParser parser = createTimestampParser(task, columnConfig);
this.timestampParserMap.put(columnConfig.getName(), parser);
}
}
}
示例11: createTimestampParser
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
private TimestampParser createTimestampParser(PluginTask task, ColumnConfig columnConfig)
{
DateTimeZone timezone = columnConfig.getTimeZone().or(task.getDefaultTimeZone());
String format = columnConfig.getFormat().or(task.getDefaultTimestampFormat());
String date = columnConfig.getDate().or(task.getDefaultDate());
return createTimestampParser(format, timezone, date);
}
示例12: asTimestamp
import org.embulk.spi.time.TimestampParser; //导入依赖的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);
}
}
示例13: ColumnVisitorImpl
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
public ColumnVisitorImpl(PluginTask task, Schema schema, PageBuilder pageBuilder, TimestampParser[] timestampParsers)
{
this.task = task;
this.schema = schema;
this.pageBuilder = pageBuilder;
this.timestampParsers = timestampParsers;
this.autoTypecasts = new Boolean[schema.size()];
buildAutoTypecasts();
}
示例14: initTimestampLiteral
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
void initTimestampLiteral(StringLiteral literal)
{
this.yytext = literal.yytext;
String[] formats = {
"%Y-%m-%d %H:%M:%S.%N %z",
"%Y-%m-%d %H:%M:%S.%N",
"%Y-%m-%d %H:%M:%S %z",
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%d %z",
"%Y-%m-%d",
};
Timestamp val = null;
TimestampParseException ex = null;
for (String format : formats) {
try {
TimestampParser timestampParser = createTimestampParser(format, defaultTimeZone);
this.val = timestampParser.parse(literal.val);
break;
}
catch (TimestampParseException e) {
ex = e;
}
}
if (this.val == null) {
throw Throwables.propagate(ex);
}
}
示例15: createTimestampParser
import org.embulk.spi.time.TimestampParser; //导入依赖的package包/类
private TimestampParser createTimestampParser(String format, DateTimeZone timezone, String date)
{
TimestampParserTaskImpl task = new TimestampParserTaskImpl(timezone, format, date);
TimestampParserColumnOptionImpl columnOption = new TimestampParserColumnOptionImpl(
Optional.of(timezone), Optional.of(format), Optional.of(date));
return new TimestampParser(task, columnOption);
}