本文整理了Java中org.apache.avro.LogicalTypes.timeMillis()
方法的一些代码示例,展示了LogicalTypes.timeMillis()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LogicalTypes.timeMillis()
方法的具体详情如下:
包路径:org.apache.avro.LogicalTypes
类名称:LogicalTypes
方法名:timeMillis
暂无
代码示例来源:origin: apache/flink
private int convertFromTime(Schema schema, Time date) {
final LogicalType logicalType = schema.getLogicalType();
if (logicalType == LogicalTypes.timeMillis()) {
// adopted from Apache Calcite
final long time = date.getTime();
final long converted = time + (long) LOCAL_TZ.getOffset(time);
return (int) (converted % 86400000L);
} else {
throw new RuntimeException("Unsupported time type.");
}
}
代码示例来源:origin: apache/avro
@Override
public Schema getRecommendedSchema() {
return LogicalTypes.timeMillis().addToSchema(Schema.create(Schema.Type.INT));
}
}
代码示例来源:origin: apache/avro
@Override
public Schema getRecommendedSchema() {
return LogicalTypes.timeMillis().addToSchema(Schema.create(Schema.Type.INT));
}
}
代码示例来源:origin: apache/flink
if (logicalType == LogicalTypes.date()) {
return Types.SQL_DATE;
} else if (logicalType == LogicalTypes.timeMillis()) {
return Types.SQL_TIME;
代码示例来源:origin: confluentinc/ksql
@Test
public void shouldDeserializeTimeMillisToBigint() {
shouldDeserializeTypeCorrectly(
LogicalTypes.timeMillis().addToSchema(
org.apache.avro.SchemaBuilder.builder().intType()),
ChronoUnit.MILLIS.between(
LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT),
LocalDateTime.now()),
Schema.OPTIONAL_INT64_SCHEMA
);
}
代码示例来源:origin: apache/avro
@Test
public void testTimeMillisConversion() throws Exception {
TimeConversion conversion = new TimeConversion();
LocalTime oneAM = new LocalTime(1, 0);
LocalTime afternoon = new LocalTime(15, 14, 15, 926);
int afternoonMillis = ((15 * 60 + 14) * 60 + 15) * 1000 + 926;
Assert.assertEquals("Midnight should be 0", 0,
(int) conversion.toInt(
LocalTime.MIDNIGHT, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
Assert.assertEquals("01:00 should be 3,600,000", 3600000,
(int) conversion.toInt(
oneAM, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
Assert.assertEquals("15:14:15.926 should be " + afternoonMillis,
afternoonMillis,
(int) conversion.toInt(
afternoon, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
Assert.assertEquals("Midnight should be 0",
LocalTime.MIDNIGHT,
conversion.fromInt(0, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
Assert.assertEquals("01:00 should be 3,600,000",
oneAM,
conversion.fromInt(
3600000, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
Assert.assertEquals("15:14:15.926 should be " + afternoonMillis,
afternoon,
conversion.fromInt(
afternoonMillis, TIME_MILLIS_SCHEMA, LogicalTypes.timeMillis()));
}
代码示例来源:origin: apache/nifi
case TIME:
schema = Schema.create(Type.INT);
LogicalTypes.timeMillis().addToSchema(schema);
break;
case TIMESTAMP:
代码示例来源: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.timeMillis().addToSchema(SchemaBuilder.builder().intType()))
: u.stringType());
break;
代码示例来源:origin: apache/avro
case TIME:
jj_consume_token(TIME);
{if (true) return LogicalTypes.timeMillis().addToSchema(Schema.create(Type.INT));}
break;
case TIMESTAMP:
代码示例来源:origin: org.apache.flink/flink-avro
private int convertFromTime(Schema schema, Time date) {
final LogicalType logicalType = schema.getLogicalType();
if (logicalType == LogicalTypes.timeMillis()) {
// adopted from Apache Calcite
final long time = date.getTime();
final long converted = time + (long) LOCAL_TZ.getOffset(time);
return (int) (converted % 86400000L);
} else {
throw new RuntimeException("Unsupported time type.");
}
}
代码示例来源:origin: com.alibaba.blink/flink-avro
private int convertFromTime(Schema schema, Time date) {
final LogicalType logicalType = schema.getLogicalType();
if (logicalType == LogicalTypes.timeMillis()) {
// adopted from Apache Calcite
final long time = date.getTime();
final long converted = time + (long) LOCAL_TZ.getOffset(time);
return (int) (converted % 86400000L);
} else {
throw new RuntimeException("Unsupported time type.");
}
}
代码示例来源:origin: org.talend.daikon/daikon
/**
* Checks whether specified schema has logical time-millis type
* It should have type INT and logical type "time-millis"
*
* @param schema avro schema
* @return true, if schema has logical time-millis type
*/
public static boolean isLogicalTimeMillis(Schema schema) {
LogicalType logicalType = schema.getLogicalType();
return Type.INT == schema.getType() && LogicalTypes.timeMillis().equals(logicalType);
}
代码示例来源:origin: org.talend.daikon/daikon
/**
* Returns schema for Avro Time-millis logical type. It's Avro type is Int
*
* @return Time-millis logical type schema
*/
public static Schema _logicalTime() {
return LogicalTypes.timeMillis().addToSchema(Schema.create(Schema.Type.INT));
}
代码示例来源:origin: org.talend.components/components-snowflake-runtime
@Override
public Object convertToAvro(ResultSet value) {
int index = f.pos() + 1;
try {
if (basicSchema.getLogicalType() == LogicalTypes.date()) {
// Snowflake stores the value as the number of days. So it is possible to retrieve that as an
// int value instead of converting it to Date first and then to days from milliseconds. If we
// convert it to date, Snowflake jdbc shifts the time to 00:00 in current timezone.
Object date = value.getObject(index);
return (date != null) ? value.getInt(index) : null;
} else if (basicSchema.getLogicalType() == LogicalTypes.timeMillis()) {
java.sql.Time time = value.getTime(index);
return (time != null) ? (int) time.getTime() : null;
} else {
java.sql.Timestamp timestamp = value.getTimestamp(index);
return (timestamp != null) ? timestamp.getTime() : null;
}
} catch (SQLException e) {
throw new ComponentException(e);
}
}
};
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!