本文整理了Java中org.apache.avro.LogicalTypes.timestampMillis()
方法的一些代码示例,展示了LogicalTypes.timestampMillis()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LogicalTypes.timestampMillis()
方法的具体详情如下:
包路径:org.apache.avro.LogicalTypes
类名称:LogicalTypes
方法名:timestampMillis
暂无
代码示例来源:origin: apache/flink
private long convertFromTimestamp(Schema schema, Timestamp date) {
final LogicalType logicalType = schema.getLogicalType();
if (logicalType == LogicalTypes.timestampMillis()) {
// adopted from Apache Calcite
final long time = date.getTime();
return time + (long) LOCAL_TZ.getOffset(time);
} else {
throw new RuntimeException("Unsupported timestamp type.");
}
}
代码示例来源:origin: apache/avro
@Override
public Schema getRecommendedSchema() {
return LogicalTypes.timestampMillis().addToSchema(Schema.create(Schema.Type.LONG));
}
}
代码示例来源:origin: apache/avro
@Override
public Schema getRecommendedSchema() {
return LogicalTypes.timestampMillis().addToSchema(Schema.create(Schema.Type.LONG));
}
}
代码示例来源:origin: apache/flink
case LONG:
if (schema.getLogicalType() == LogicalTypes.timestampMillis()) {
return Types.SQL_TIMESTAMP;
代码示例来源:origin: apache/avro
@Test
public void testTimestampMillisConversion() throws Exception {
TimestampConversion conversion = new TimestampConversion();
long nowInstant = new Date().getTime();
DateTime now = conversion.fromLong(
nowInstant, TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis());
long roundTrip = conversion.toLong(
now, TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis());
Assert.assertEquals("Round-trip conversion should work",
nowInstant, roundTrip);
long May_28_2015_21_46_53_221_instant = 1432849613221L;
DateTime May_28_2015_21_46_53_221 =
new DateTime(2015, 5, 28, 21, 46, 53, 221, DateTimeZone.UTC);
Assert.assertEquals("Known date should be correct",
May_28_2015_21_46_53_221,
conversion.fromLong(May_28_2015_21_46_53_221_instant,
TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
Assert.assertEquals("Known date should be correct",
May_28_2015_21_46_53_221_instant,
(long) conversion.toLong(May_28_2015_21_46_53_221,
TIMESTAMP_MILLIS_SCHEMA, LogicalTypes.timestampMillis()));
}
代码示例来源:origin: confluentinc/ksql
@Test
public void shouldDeserializeTimestampToBigint() {
shouldDeserializeTypeCorrectly(
LogicalTypes.timestampMillis().addToSchema(
org.apache.avro.SchemaBuilder.builder().longType()),
ChronoUnit.MILLIS.between(
LocalDateTime.of(LocalDate.ofEpochDay(0), LocalTime.MIDNIGHT),
LocalDateTime.now()),
Schema.OPTIONAL_INT64_SCHEMA
);
}
代码示例来源:origin: apache/nifi
case TIMESTAMP:
schema = Schema.create(Type.LONG);
LogicalTypes.timestampMillis().addToSchema(schema);
break;
default:
代码示例来源:origin: apache/avro
@BeforeClass
public static void createSchemas() {
TestJsr310TimeConversions.DATE_SCHEMA = LogicalTypes.date()
.addToSchema(Schema.create(Schema.Type.INT));
TestJsr310TimeConversions.TIME_MILLIS_SCHEMA = LogicalTypes.timeMillis()
.addToSchema(Schema.create(Schema.Type.INT));
TestJsr310TimeConversions.TIME_MICROS_SCHEMA = LogicalTypes.timeMicros()
.addToSchema(Schema.create(Schema.Type.LONG));
TestJsr310TimeConversions.TIMESTAMP_MILLIS_SCHEMA = LogicalTypes.timestampMillis()
.addToSchema(Schema.create(Schema.Type.LONG));
TestJsr310TimeConversions.TIMESTAMP_MICROS_SCHEMA = LogicalTypes.timestampMicros()
.addToSchema(Schema.create(Schema.Type.LONG));
}
代码示例来源:origin: apache/avro
@BeforeClass
public static void createSchemas() {
TestTimeConversions.DATE_SCHEMA = LogicalTypes.date()
.addToSchema(Schema.create(Schema.Type.INT));
TestTimeConversions.TIME_MILLIS_SCHEMA = LogicalTypes.timeMillis()
.addToSchema(Schema.create(Schema.Type.INT));
TestTimeConversions.TIME_MICROS_SCHEMA = LogicalTypes.timeMicros()
.addToSchema(Schema.create(Schema.Type.LONG));
TestTimeConversions.TIMESTAMP_MILLIS_SCHEMA = LogicalTypes.timestampMillis()
.addToSchema(Schema.create(Schema.Type.LONG));
TestTimeConversions.TIMESTAMP_MICROS_SCHEMA = LogicalTypes.timestampMicros()
.addToSchema(Schema.create(Schema.Type.LONG));
}
代码示例来源:origin: apache/nifi
addNullableField(builder, columnName,
u -> options.useLogicalTypes
? u.type(LogicalTypes.timestampMillis().addToSchema(SchemaBuilder.builder().longType()))
: u.stringType());
break;
代码示例来源:origin: apache/avro
case TIMESTAMP:
jj_consume_token(TIMESTAMP);
{if (true) return LogicalTypes.timestampMillis().addToSchema(Schema.create(Type.LONG));}
break;
case DECIMAL:
代码示例来源:origin: com.alibaba.blink/flink-avro
private long convertFromTimestamp(Schema schema, Timestamp date) {
final LogicalType logicalType = schema.getLogicalType();
if (logicalType == LogicalTypes.timestampMillis()) {
// adopted from Apache Calcite
final long time = date.getTime();
return time + (long) LOCAL_TZ.getOffset(time);
} else {
throw new RuntimeException("Unsupported timestamp type.");
}
}
代码示例来源:origin: org.talend.daikon/daikon
/**
* Checks whether specified schema has logical timestamp-millis type.
* Its type should be LONG and
* Its logical type should be "timestamp-millis"
*
* @param schema avro schema
* @return true, if schema has logical timestamp-millis type
*/
public static boolean isLogicalTimestampMillis(Schema schema) {
LogicalType logicalType = schema.getLogicalType();
return Type.LONG == schema.getType() && LogicalTypes.timestampMillis().equals(logicalType);
}
代码示例来源:origin: org.apache.flink/flink-avro
private long convertFromTimestamp(Schema schema, Timestamp date) {
final LogicalType logicalType = schema.getLogicalType();
if (logicalType == LogicalTypes.timestampMillis()) {
// adopted from Apache Calcite
final long time = date.getTime();
return time + (long) LOCAL_TZ.getOffset(time);
} else {
throw new RuntimeException("Unsupported timestamp type.");
}
}
代码示例来源:origin: GoogleCloudPlatform/DataflowTemplates
private Optional<Timestamp> readTimestamp(
GenericRecord record, Schema.Type avroType, LogicalType logicalType, String fieldName) {
switch (avroType) {
case LONG:
if (LogicalTypes.timestampMillis().equals(logicalType)) {
return Optional.ofNullable((Long) record.get(fieldName))
.map(x -> Timestamp.ofTimeMicroseconds(1000L * x));
}
if (LogicalTypes.timestampMicros().equals(logicalType)) {
return Optional.ofNullable((Long) record.get(fieldName))
.map(Timestamp::ofTimeMicroseconds);
}
// Default to micro-seconds.
return Optional.ofNullable((Long) record.get(fieldName)).map(Timestamp::ofTimeMicroseconds);
case STRING:
return Optional.ofNullable((Utf8) record.get(fieldName))
.map(Utf8::toString)
.map(Timestamp::parseTimestamp);
default:
throw new IllegalArgumentException("Cannot interpret " + avroType + " as TIMESTAMP");
}
}
代码示例来源:origin: org.talend.daikon/daikon
/**
* Returns schema for Avro Timestamp-millis logical type. It's Avro type is Long
*
* @return Timestamp-millis logical type schema
*/
public static Schema _logicalTimestamp() {
return LogicalTypes.timestampMillis().addToSchema(Schema.create(Schema.Type.LONG));
}
代码示例来源:origin: org.talend.components/components-snowflake-runtime
protected Object getFieldValue(Object inputValue, Field field) {
Schema s = AvroUtils.unwrapIfNullable(field.schema());
if (inputValue != null && inputValue instanceof String && ((String) inputValue).isEmpty()) {
return emptyStringValue;
} else if (null == inputValue || inputValue instanceof String) {
return inputValue;
} else if (AvroUtils.isSameType(s, AvroUtils._date())) {
Date date = (Date) inputValue;
return date.getTime();
} else if (LogicalTypes.fromSchemaIgnoreInvalid(s) == LogicalTypes.timeMillis()) {
return formatter.formatTimeMillis(inputValue);
} else if (LogicalTypes.fromSchemaIgnoreInvalid(s) == LogicalTypes.date()) {
return formatter.formatDate(inputValue);
} else if (LogicalTypes.fromSchemaIgnoreInvalid(s) == LogicalTypes.timestampMillis()) {
return formatter.formatTimestampMillis(inputValue);
} else {
return inputValue;
}
}
代码示例来源:origin: Talend/components
private Object formatIfAnySnowflakeDateType(Object inputValue, Schema s) {
if (LogicalTypes.fromSchemaIgnoreInvalid(s) == LogicalTypes.timeMillis()) {
return formatter.formatTimeMillis(inputValue);
} else if (LogicalTypes.fromSchemaIgnoreInvalid(s) == LogicalTypes.date()) {
return formatter.formatDate(inputValue);
} else if (LogicalTypes.fromSchemaIgnoreInvalid(s) == LogicalTypes.timestampMillis()) {
return formatter.formatTimestampMillis(inputValue);
} else {
return inputValue;
}
}
代码示例来源:origin: org.apache.parquet/parquet-avro
private LogicalType convertOriginalType(OriginalType annotation, DecimalMetadata meta) {
if (annotation == null) {
return null;
}
switch (annotation) {
case DECIMAL:
return LogicalTypes.decimal(meta.getPrecision(), meta.getScale());
case DATE:
return LogicalTypes.date();
case TIME_MILLIS:
return LogicalTypes.timeMillis();
case TIME_MICROS:
return LogicalTypes.timeMicros();
case TIMESTAMP_MILLIS:
return LogicalTypes.timestampMillis();
case TIMESTAMP_MICROS:
return LogicalTypes.timestampMicros();
}
return null;
}
代码示例来源:origin: org.talend.components/processing-runtime
/**
* Generate a schema from output type and format
*
* @param outputType
* @param outputFormat
* @return
*/
public static Schema getSchema(TypeConverterOutputTypes outputType, String outputFormat) {
Schema result = Schema.create(outputType.getTargetType());
switch (outputType) {
case Date:
result = LogicalTypes.date().addToSchema(result);
break;
case Time:
result = LogicalTypes.timeMillis().addToSchema(result);
break;
case DateTime:
result = LogicalTypes.timestampMillis().addToSchema(result);
break;
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!