本文整理汇总了Java中org.embulk.spi.util.Timestamps.newTimestampColumnParsers方法的典型用法代码示例。如果您正苦于以下问题:Java Timestamps.newTimestampColumnParsers方法的具体用法?Java Timestamps.newTimestampColumnParsers怎么用?Java Timestamps.newTimestampColumnParsers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.embulk.spi.util.Timestamps
的用法示例。
在下文中一共展示了Timestamps.newTimestampColumnParsers方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.embulk.spi.util.Timestamps; //导入方法依赖的package包/类
public static List<DateParser> create(GrokParserPlugin.PluginTask task) {
switch (task.getTimestampParser().toLowerCase()) {
case "ruby":
TimestampParser[] ps = Timestamps.newTimestampColumnParsers(task, task.getColumns());
return Arrays.stream(ps)
.map(parser -> (DateParser) (text) -> parser.parse(text))
.collect(Collectors.toList());
case "epoch":
return task.getColumns().getColumns().stream()
.map(x -> (DateParser) (text) -> Timestamp.ofEpochMilli(Long.parseLong(text)))
.collect(Collectors.toList());
case "sdf":
case "simpledateformat":
default:
SimpleDateFormat[] parsers = new SimpleDateFormat[task.getColumns().getColumnCount()];
int i = 0;
for (ColumnConfig column : task.getColumns().getColumns()) {
if (column.getType() instanceof TimestampType) {
TimestampColumnOption option = column.getOption().loadConfig(TimestampColumnOption.class);
String format = convertToJavaDateFormat(option.getFormat().or("yyyy-MM-dd HH:MM:ss.SSS z"));
SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.ENGLISH);
sdf.setTimeZone(option.getTimeZone().or(DateTimeZone.UTC).toTimeZone());
parsers[i] = sdf;
}
i++;
}
return Arrays.stream(parsers).map(parser ->
(DateParser) (String date) -> {
try {
return Timestamp.ofEpochMilli(parser.parse(date).getTime());
} catch (ParseException e) {
throw new GrokRecordValidateException(e);
}
}).collect(Collectors.toList());
}
}
示例2: getTimestampParser
import org.embulk.spi.util.Timestamps; //导入方法依赖的package包/类
protected final TimestampParser getTimestampParser(Column column) {
if (timestampParsers == null) {
PluginTask task = visitorValue.getPluginTask();
timestampParsers = Timestamps.newTimestampColumnParsers(task, task.getColumns());
}
return timestampParsers[column.getIndex()];
}
示例3: ColumnVisitorImpl
import org.embulk.spi.util.Timestamps; //导入方法依赖的package包/类
ColumnVisitorImpl(Map<String, String> row, PluginTask task, PageBuilder pageBuilder) {
this.row = row;
this.pageBuilder = pageBuilder;
this.timestampParsers = Timestamps.newTimestampColumnParsers(
task, task.getColumns());
}
示例4: run
import org.embulk.spi.util.Timestamps; //导入方法依赖的package包/类
@Override
public void run(TaskSource taskSource, Schema schema, FileInput input, PageOutput output)
{
PluginTask task = taskSource.loadTask(PluginTask.class);
setColumnNameValues(schema);
final SchemaConfig schemaConfig = getSchemaConfig(task);
final TimestampParser[] timestampParsers = Timestamps.newTimestampColumnParsers(task, schemaConfig);
final LineDecoder decoder = newLineDecoder(input, task);
final JsonParser jsonParser = newJsonParser();
final boolean stopOnInvalidRecord = task.getStopOnInvalidRecord();
try (final PageBuilder pageBuilder = new PageBuilder(Exec.getBufferAllocator(), schema, output)) {
ColumnVisitorImpl visitor = new ColumnVisitorImpl(task, schema, pageBuilder, timestampParsers);
while (decoder.nextFile()) { // TODO this implementation should be improved with new JsonParser API on Embulk v0.8.3
lineNumber = 0;
while ((line = decoder.poll()) != null) {
lineNumber++;
try {
Value value = jsonParser.parse(line);
if (!value.isMapValue()) {
throw new JsonRecordValidateException("Json string is not representing map value.");
}
final Map<Value, Value> record = value.asMapValue().map();
for (Column column : schema.getColumns()) {
Value v = record.get(getColumnNameValue(column));
visitor.setValue(v);
column.visit(visitor);
}
pageBuilder.addRecord();
}
catch (JsonRecordValidateException | JsonParseException e) {
if (stopOnInvalidRecord) {
throw new DataException(String.format("Invalid record at line %d: %s", lineNumber, line), e);
}
log.warn(String.format("Skipped line %d (%s): %s", lineNumber, e.getMessage(), line));
}
}
}
pageBuilder.finish();
}
}
示例5: run
import org.embulk.spi.util.Timestamps; //导入方法依赖的package包/类
@Override
public void run(TaskSource taskSource, Schema schema, FileInput input, PageOutput output) {
PluginTask task = taskSource.loadTask(PluginTask.class);
LineDecoder lineDecoder = new LineDecoder(input, task);
PageBuilder pageBuilder = new PageBuilder(Exec.getBufferAllocator(), schema, output);
TimestampParser[] timestampParsers = Timestamps.newTimestampColumnParsers(task, task.getSchemaConfig());
Pattern pattern = Pattern.compile(task.getRegex());
Map<String, DynamicColumnSetter> setterMap = setupSetters(pageBuilder, task.getSchemaConfig(),
timestampParsers, taskSource.loadTask(PluginTaskFormatter.class));
while (input.nextFile()) {
int lineNumber = 0;
while (true) {
String line = lineDecoder.poll();
lineNumber++;
if (line == null) {
break;
}
Matcher matcher = pattern.matcher(line);
if (!matcher.matches()) {
if (task.getSkipIfUnmatch()) {
log.warn(String.format("Skipped unmatched line %d: %s", lineNumber, line));
continue;
} else {
throw new DataException(String.format("Unmatched Line at line %d: %s", lineNumber, line));
}
}
for (Map.Entry<String, DynamicColumnSetter> pair : setterMap.entrySet()) {
String value = matcher.group(pair.getKey());
if (value == null) {
pair.getValue().setNull();
} else {
pair.getValue().set(value);
}
}
pageBuilder.addRecord();
}
}
pageBuilder.finish();
}