• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Time类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.kafka.connect.data.Time的典型用法代码示例。如果您正苦于以下问题:Java Time类的具体用法?Java Time怎么用?Java Time使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Time类属于org.apache.kafka.connect.data包,在下文中一共展示了Time类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: timestampTypeFromSchema

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
/**
 * Determine the type/format of the timestamp based on the schema
 */
private String timestampTypeFromSchema(Schema schema) {
    if (Timestamp.LOGICAL_NAME.equals(schema.name())) {
        return TYPE_TIMESTAMP;
    } else if (org.apache.kafka.connect.data.Date.LOGICAL_NAME.equals(schema.name())) {
        return TYPE_DATE;
    } else if (Time.LOGICAL_NAME.equals(schema.name())) {
        return TYPE_TIME;
    } else if (schema.type().equals(Schema.Type.STRING)) {
        // If not otherwise specified, string == user-specified string format for timestamps
        return TYPE_STRING;
    } else if (schema.type().equals(Schema.Type.INT64)) {
        // If not otherwise specified, long == unix time
        return TYPE_UNIX;
    }
    throw new ConnectException("Schema " + schema + " does not correspond to a known timestamp type format");
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:20,代码来源:TimestampConverter.java


示例2: Parser

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
public Parser() {
  this.typeParsers = new HashMap<>();
  registerTypeParser(Schema.BOOLEAN_SCHEMA, new BooleanParser());
  registerTypeParser(Schema.BOOLEAN_SCHEMA, new BooleanParser());
  registerTypeParser(Schema.FLOAT32_SCHEMA, new Float32TypeParser());
  registerTypeParser(Schema.FLOAT64_SCHEMA, new Float64TypeParser());
  registerTypeParser(Schema.INT8_SCHEMA, new Int8TypeParser());
  registerTypeParser(Schema.INT16_SCHEMA, new Int16TypeParser());
  registerTypeParser(Schema.INT32_SCHEMA, new Int32TypeParser());
  registerTypeParser(Schema.INT64_SCHEMA, new Int64TypeParser());
  registerTypeParser(Schema.STRING_SCHEMA, new StringTypeParser());
  registerTypeParser(Decimal.schema(1), new DecimalTypeParser());
  registerTypeParser(Date.SCHEMA, new DateTypeParser());
  registerTypeParser(Time.SCHEMA, new TimeTypeParser());
  registerTypeParser(Timestamp.SCHEMA, new TimestampTypeParser());
}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:17,代码来源:Parser.java


示例3: nullableTests

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Test
public void nullableTests() {
  final Schema[] schemas = new Schema[]{
      Schema.OPTIONAL_BOOLEAN_SCHEMA,
      Schema.OPTIONAL_FLOAT32_SCHEMA,
      Schema.OPTIONAL_FLOAT64_SCHEMA,
      Schema.OPTIONAL_INT8_SCHEMA,
      Schema.OPTIONAL_INT16_SCHEMA,
      Schema.OPTIONAL_INT32_SCHEMA,
      Schema.OPTIONAL_INT64_SCHEMA,
      Schema.OPTIONAL_STRING_SCHEMA,
      Decimal.builder(1).optional().build(),
      Timestamp.builder().optional().build(),
      Date.builder().optional().build(),
      Time.builder().optional().build(),
  };

  for (Schema schema : schemas) {
    Object actual = this.parser.parseString(schema, null);
    assertNull(actual);
  }

}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:24,代码来源:StringParserTest.java


示例4: start

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Override
public void start(Map<String, String> settings) {
  this.config = config(settings);

  checkDirectory(SpoolDirSourceConnectorConfig.INPUT_PATH_CONFIG, this.config.inputPath);
  checkDirectory(SpoolDirSourceConnectorConfig.FINISHED_PATH_CONFIG, this.config.finishedPath);
  checkDirectory(SpoolDirSourceConnectorConfig.ERROR_PATH_CONFIG, this.config.errorPath);

  this.parser = new Parser();
  Map<Schema, TypeParser> dateTypeParsers = ImmutableMap.of(
      Timestamp.SCHEMA, new TimestampTypeParser(this.config.parserTimestampTimezone, this.config.parserTimestampDateFormats),
      Date.SCHEMA, new DateTypeParser(this.config.parserTimestampTimezone, this.config.parserTimestampDateFormats),
      Time.SCHEMA, new TimeTypeParser(this.config.parserTimestampTimezone, this.config.parserTimestampDateFormats)
  );

  for (Map.Entry<Schema, TypeParser> kvp : dateTypeParsers.entrySet()) {
    this.parser.registerTypeParser(kvp.getKey(), kvp.getValue());
  }
}
 
开发者ID:jcustenborder,项目名称:kafka-connect-spooldir,代码行数:20,代码来源:SpoolDirSourceTask.java


示例5: inferLogicalMapping

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
private static JsonNode inferLogicalMapping(Schema schema) {
  String schemaName = schema.name();
  Object defaultValue = schema.defaultValue();
  if (schemaName == null) {
    return null;
  }

  switch (schemaName) {
    case Date.LOGICAL_NAME:
    case Time.LOGICAL_NAME:
    case Timestamp.LOGICAL_NAME:
      return inferPrimitive(ElasticsearchSinkConnectorConstants.DATE_TYPE, defaultValue);
    case Decimal.LOGICAL_NAME:
      return inferPrimitive(ElasticsearchSinkConnectorConstants.DOUBLE_TYPE, defaultValue);
    default:
      // User-defined type or unknown built-in
      return null;
  }
}
 
开发者ID:confluentinc,项目名称:kafka-connect-elasticsearch,代码行数:20,代码来源:Mapping.java


示例6: createSchema

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
protected Schema createSchema() {
  Schema structSchema = createInnerSchema();
  return SchemaBuilder.struct().name("record")
      .field("boolean", Schema.BOOLEAN_SCHEMA)
      .field("bytes", Schema.BYTES_SCHEMA)
      .field("int8", Schema.INT8_SCHEMA)
      .field("int16", Schema.INT16_SCHEMA)
      .field("int32", Schema.INT32_SCHEMA)
      .field("int64", Schema.INT64_SCHEMA)
      .field("float32", Schema.FLOAT32_SCHEMA)
      .field("float64", Schema.FLOAT64_SCHEMA)
      .field("string", Schema.STRING_SCHEMA)
      .field("array", SchemaBuilder.array(Schema.STRING_SCHEMA).build())
      .field("map", SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.STRING_SCHEMA).build())
      .field("struct", structSchema)
      .field("decimal", Decimal.schema(2))
      .field("date", Date.SCHEMA)
      .field("time", Time.SCHEMA)
      .field("timestamp", Timestamp.SCHEMA)
      .build();
}
 
开发者ID:confluentinc,项目名称:kafka-connect-elasticsearch,代码行数:22,代码来源:MappingTest.java


示例7: createInnerSchema

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
private Schema createInnerSchema() {
  return SchemaBuilder.struct().name("inner")
      .field("boolean", Schema.BOOLEAN_SCHEMA)
      .field("bytes", Schema.BYTES_SCHEMA)
      .field("int8", Schema.INT8_SCHEMA)
      .field("int16", Schema.INT16_SCHEMA)
      .field("int32", Schema.INT32_SCHEMA)
      .field("int64", Schema.INT64_SCHEMA)
      .field("float32", Schema.FLOAT32_SCHEMA)
      .field("float64", Schema.FLOAT64_SCHEMA)
      .field("string", Schema.STRING_SCHEMA)
      .field("array", SchemaBuilder.array(Schema.STRING_SCHEMA).build())
      .field("map", SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.STRING_SCHEMA).build())
      .field("decimal", Decimal.schema(2))
      .field("date", Date.SCHEMA)
      .field("time", Time.SCHEMA)
      .field("timestamp", Timestamp.SCHEMA)
      .build();
}
 
开发者ID:confluentinc,项目名称:kafka-connect-elasticsearch,代码行数:20,代码来源:MappingTest.java


示例8: testWithSchemaTimestampToTime

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Test
public void testWithSchemaTimestampToTime() {
    TimestampConverter<SourceRecord> xform = new TimestampConverter.Value<>();
    xform.configure(Collections.singletonMap(TimestampConverter.TARGET_TYPE_CONFIG, "Time"));
    SourceRecord transformed = xform.apply(new SourceRecord(null, null, "topic", 0, Timestamp.SCHEMA, DATE_PLUS_TIME.getTime()));

    assertEquals(Time.SCHEMA, transformed.valueSchema());
    assertEquals(TIME.getTime(), transformed.value());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:TimestampConverterTest.java


示例9: testWithSchemaTimeToTimestamp

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Test
public void testWithSchemaTimeToTimestamp() {
    TimestampConverter<SourceRecord> xform = new TimestampConverter.Value<>();
    xform.configure(Collections.singletonMap(TimestampConverter.TARGET_TYPE_CONFIG, "Timestamp"));
    SourceRecord transformed = xform.apply(new SourceRecord(null, null, "topic", 0, Time.SCHEMA, TIME.getTime()));

    assertEquals(Timestamp.SCHEMA, transformed.valueSchema());
    // No change expected since the source type is coarser-grained
    assertEquals(TIME.getTime(), transformed.value());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:11,代码来源:TimestampConverterTest.java


示例10: timeToConnect

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Test
public void timeToConnect() {
    Schema schema = Time.SCHEMA;
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MILLISECOND, 14400000);
    java.util.Date reference = calendar.getTime();
    String msg = "{ \"schema\": { \"type\": \"int32\", \"name\": \"org.apache.kafka.connect.data.Time\", \"version\": 1 }, \"payload\": 14400000 }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    java.util.Date converted = (java.util.Date) schemaAndValue.value();
    assertEquals(schema, schemaAndValue.schema());
    assertEquals(reference, converted);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:JsonConverterTest.java


示例11: timeToConnectOptional

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Test
public void timeToConnectOptional() {
    Schema schema = Time.builder().optional().schema();
    String msg = "{ \"schema\": { \"type\": \"int32\", \"name\": \"org.apache.kafka.connect.data.Time\", \"version\": 1, \"optional\": true }, \"payload\": null }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    assertEquals(schema, schemaAndValue.schema());
    assertNull(schemaAndValue.value());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:9,代码来源:JsonConverterTest.java


示例12: timeToConnectWithDefaultValue

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Test
public void timeToConnectWithDefaultValue() {
    java.util.Date reference = new java.util.Date(0);
    Schema schema = Time.builder().defaultValue(reference).schema();
    String msg = "{ \"schema\": { \"type\": \"int32\", \"name\": \"org.apache.kafka.connect.data.Time\", \"version\": 1, \"default\": 0 }, \"payload\": null }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    assertEquals(schema, schemaAndValue.schema());
    assertEquals(reference, schemaAndValue.value());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:JsonConverterTest.java


示例13: timeToConnectOptionalWithDefaultValue

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Test
public void timeToConnectOptionalWithDefaultValue() {
    java.util.Date reference = new java.util.Date(0);
    Schema schema = Time.builder().optional().defaultValue(reference).schema();
    String msg = "{ \"schema\": { \"type\": \"int32\", \"name\": \"org.apache.kafka.connect.data.Time\", \"version\": 1, \"optional\": true, \"default\": 0 }, \"payload\": null }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    assertEquals(schema, schemaAndValue.schema());
    assertEquals(reference, schemaAndValue.value());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:JsonConverterTest.java


示例14: timeToJson

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Test
public void timeToJson() throws IOException {
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MILLISECOND, 14400000);
    java.util.Date date = calendar.getTime();

    JsonNode converted = parse(converter.fromConnectData(TOPIC, Time.SCHEMA, date));
    validateEnvelope(converted);
    assertEquals(parse("{ \"type\": \"int32\", \"optional\": false, \"name\": \"org.apache.kafka.connect.data.Time\", \"version\": 1 }"),
            converted.get(JsonSchema.ENVELOPE_SCHEMA_FIELD_NAME));
    JsonNode payload = converted.get(JsonSchema.ENVELOPE_PAYLOAD_FIELD_NAME);
    assertTrue(payload.isInt());
    assertEquals(14400000, payload.longValue());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:16,代码来源:JsonConverterTest.java


示例15: time

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
static Object time(Schema schema, Object value) {
  if (value instanceof Number) {
    Number number = (Number) value;
    return Time.toLogical(schema, number.intValue());
  }
  return value;
}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:8,代码来源:ValueHelper.java


示例16: nullableTests

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Test
public void nullableTests() throws IOException {
  final Schema[] schemas = new Schema[]{
      Schema.OPTIONAL_BOOLEAN_SCHEMA,
      Schema.OPTIONAL_FLOAT32_SCHEMA,
      Schema.OPTIONAL_FLOAT64_SCHEMA,
      Schema.OPTIONAL_INT8_SCHEMA,
      Schema.OPTIONAL_INT16_SCHEMA,
      Schema.OPTIONAL_INT32_SCHEMA,
      Schema.OPTIONAL_INT64_SCHEMA,
      Schema.OPTIONAL_STRING_SCHEMA,
      Decimal.builder(1).optional().build(),
      Timestamp.builder().optional().build(),
      Date.builder().optional().build(),
      Time.builder().optional().build(),
  };

  for (Schema schema : schemas) {
    JsonNode inputNode = null;
    Object actual = this.parser.parseJsonNode(schema, inputNode);
    assertNull(actual);
    inputNode = objectMapper.readTree("{\"foo\": null}");
    inputNode = inputNode.findValue("foo");
    actual = this.parser.parseJsonNode(schema, inputNode);
    assertNull(actual);
  }

}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:29,代码来源:JsonNodeTest.java


示例17: timeTests

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
@Test
public void timeTests() throws ParseException {
  SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

  Map<String, ?> tests = ImmutableMap.of(
      "12:08:56", dateFormat.parse("12:08:56")
  );
  Map<String, java.util.Date> results = assertConversion(Time.SCHEMA, java.util.Date.class, tests);
  for (Map.Entry<String, java.util.Date> kvp : results.entrySet()) {
    Time.fromLogical(Time.SCHEMA, kvp.getValue());
  }
}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:13,代码来源:StringParserTest.java


示例18: toJsonMap

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
public static Map<String, Object> toJsonMap(Struct struct) {
    Map<String, Object> jsonMap = new HashMap<String, Object>(0);
    List<Field> fields = struct.schema().fields();
    for (Field field : fields) {
        String fieldName = field.name();
        Schema.Type fieldType = field.schema().type();
        String schemaName=field.schema().name();
        switch (fieldType) {
            case STRING:
                jsonMap.put(fieldName, struct.getString(fieldName));
                break;
            case INT32:
            	if (Date.LOGICAL_NAME.equals(schemaName) 
            			|| Time.LOGICAL_NAME.equals(schemaName)) {
            		jsonMap.put(fieldName, (java.util.Date) struct.get(fieldName));
            	} else {
            		jsonMap.put(fieldName, struct.getInt32(fieldName));
            	}
                break;
            case INT16:
                jsonMap.put(fieldName, struct.getInt16(fieldName));
                break;
            case INT64:
            	if (Timestamp.LOGICAL_NAME.equals(schemaName)) {
            		jsonMap.put(fieldName, (java.util.Date) struct.get(fieldName));
            	} else {
            		jsonMap.put(fieldName, struct.getInt64(fieldName));
            	}
                break;
            case FLOAT32:
                jsonMap.put(fieldName, struct.getFloat32(fieldName));
                break;
            case STRUCT:
                jsonMap.put(fieldName, toJsonMap(struct.getStruct(fieldName)));
                break;
        }
    }
    return jsonMap;
}
 
开发者ID:DataReply,项目名称:kafka-connect-mongodb,代码行数:40,代码来源:SchemaUtils.java


示例19: preProcessSchema

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
Schema preProcessSchema(Schema schema) {
  if (schema == null) {
    return null;
  }
  // Handle logical types
  String schemaName = schema.name();
  if (schemaName != null) {
    switch (schemaName) {
      case Decimal.LOGICAL_NAME:
        return copySchemaBasics(schema, SchemaBuilder.float64()).build();
      case Date.LOGICAL_NAME:
      case Time.LOGICAL_NAME:
      case Timestamp.LOGICAL_NAME:
        return schema;
      default:
        // User type or unknown logical type
        break;
    }
  }

  Schema.Type schemaType = schema.type();
  switch (schemaType) {
    case ARRAY:
      return preProcessArraySchema(schema);
    case MAP:
      return preProcessMapSchema(schema);
    case STRUCT:
      return preProcessStructSchema(schema);
    default:
      return schema;
  }
}
 
开发者ID:confluentinc,项目名称:kafka-connect-elasticsearch,代码行数:33,代码来源:DataConverter.java


示例20: preProcessLogicalValue

import org.apache.kafka.connect.data.Time; //导入依赖的package包/类
private Object preProcessLogicalValue(String schemaName, Object value) {
  switch (schemaName) {
    case Decimal.LOGICAL_NAME:
      return ((BigDecimal) value).doubleValue();
    case Date.LOGICAL_NAME:
    case Time.LOGICAL_NAME:
    case Timestamp.LOGICAL_NAME:
      return value;
    default:
      // User-defined type or unknown built-in
      return null;
  }
}
 
开发者ID:confluentinc,项目名称:kafka-connect-elasticsearch,代码行数:14,代码来源:DataConverter.java



注:本文中的org.apache.kafka.connect.data.Time类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RefreshServiceAclResponseProto类代码示例发布时间:2022-05-22
下一篇:
Java UsernamePasswordCredentials类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap