APISonar


com.streamsets.pipeline.api.Field.Type.TIME

> com > streamsets > pipeline > api > Field > Type > TIME
com APIs streamsets APIs pipeline APIs api APIs Field APIs Type APIs TIME APIs

Example 1
public void testGenerateTime() throws OnRecordErrorException {
    Record record = RecordCreator.create();
    record.set(Field.create(Field.Type.LIST_MAP, ImmutableMap.of(
      "time", Field.create(Field.Type.TIME, new Date())
    )));

    generateAndValidateSchema(
      record,
      "{\"name\":\"time\",\"type\":{\"type\":\"int\",\"logicalType\":\"time-millis\"}}"
    );
  }
Example 2
public void testCreateTimeMillisField() throws Exception {
    String schema = "{\"name\": \"name\", \"type\": \"int\", \"logicalType\": \"time-millis\"}";
    Schema avroSchema = new Schema.Parser().parse(schema);
    Record record = RecordCreator.create();
    Field field = AvroTypeUtil.avroToSdcField(record, avroSchema, 1000);
    Assert.assertEquals(Field.Type.TIME, field.getType());
    Assert.assertEquals("time-millis", field.getAttribute(AvroTypeUtil.FIELD_ATTRIBUTE_TYPE));
    Assert.assertEquals(new Date(1000L), field.getValueAsDate());

    record.set(field);
    Object avroObject = AvroTypeUtil.sdcRecordToAvro(record, avroSchema, new HashMap<>());
    Assert.assertTrue(avroObject instanceof Integer);
    Assert.assertEquals(1000, (int)avroObject);
  }
Example 3
public static String getOffsetFormatFromColumns(TableContext tableContext, Map<String, Field> fields) {
    List<String> offsetColumnFormat = new ArrayList<>();
    for (String offsetColumn : tableContext.getOffsetColumns()) {
      Field field = fields.get(offsetColumn);
      Object value = field.getType().isOneOf(Field.Type.DATETIME, Field.Type.DATE, Field.Type.TIME)?
          //For DATE/TIME fields store the long in string format and convert back to date when using offset
          //in query
          String.valueOf(field.getValueAsDatetime().getTime())
          : field.getValue();
      offsetColumnFormat.add(String.format(OFFSET_COLUMN_NAME_VALUE, offsetColumn, value));
    }
    return OFFSET_COLUMN_JOINER.join(offsetColumnFormat);
  }
Example 4
private long getTime(Record record) throws OnRecordErrorException {
    Field timeField = record.get(conf.timeField);
    if (timeField.getType() == Field.Type.DATE ||
        timeField.getType() == Field.Type.DATETIME ||
        timeField.getType() == Field.Type.TIME)
    {
      return timeField.getValueAsDatetime().getTime();
    } else if (timeField.getType() == Field.Type.LONG) {
      return timeField.getValueAsLong();
    }

    throw new OnRecordErrorException(Errors.INFLUX_09, timeField.getType());
  }