APISonar


com.streamsets.pipeline.api.Field.Type.DATE

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

Example 1
public static Matcher<Field> dateFieldWithValue(final Date date) {
    return new FieldMatcher(Field.Type.DATE, date) {
      @Override
      protected Object getValueFromField(Field field) {
        return field.getValueAsDate();
      }
    };
  }
Example 2
public void testGenerateDate() throws OnRecordErrorException {
    Record record = RecordCreator.create();
    record.set(Field.create(Field.Type.LIST_MAP, ImmutableMap.of(
      "date", Field.create(Field.Type.DATE, new Date())
    )));

    generateAndValidateSchema(
      record,
      "{\"name\":\"date\",\"type\":{\"type\":\"int\",\"logicalType\":\"date\"}}"
    );
  }
Example 3
public void testCreateDateField() throws Exception {
    String schema = "{\"name\": \"name\", \"type\": \"int\", \"logicalType\": \"date\"}";
    Schema avroSchema = new Schema.Parser().parse(schema);
    Record record = RecordCreator.create();
    Field field = AvroTypeUtil.avroToSdcField(record, avroSchema, new Date(116, 0, 1));
    Assert.assertEquals(Field.Type.DATE, field.getType());
    Assert.assertEquals("date", field.getAttribute(AvroTypeUtil.FIELD_ATTRIBUTE_TYPE));
    Assert.assertEquals(new Date(116, 0, 1), field.getValueAsDate());

    record.set(field);
    Object avroObject = AvroTypeUtil.sdcRecordToAvro(record, avroSchema, new HashMap<String, Object>());
    Assert.assertTrue(avroObject instanceof Integer);
    Assert.assertEquals(16801, (int)avroObject);
  }
Example 4
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 5
private long getTime(Record record) throws OnRecordErrorException {
    Field timeField = record.get(conf.timeField);
    if (timeField.getType() == Field.Type.DATE || timeField.getType() == Field.Type.DATETIME) {
      return timeField.getValueAsDatetime().getTime();
    } else if (timeField.getType() == Field.Type.LONG) {
      return timeField.getValueAsLong();
    }

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