protected TableSchema createTestSchema() { return TableSchema.builder() .field(FIELD_KEY, Types.LONG()) .field(FIELD_FRUIT_NAME, Types.STRING()) .field(FIELD_COUNT, Types.DECIMAL()) .field(FIELD_TS, Types.SQL_TIMESTAMP()) .build(); }
.field(FRUIT_NAME, Types.STRING()) .field(COUNT, Types.DECIMAL()) .field(EVENT_TIME, Types.SQL_TIMESTAMP()) .field(PROC_TIME, Types.SQL_TIMESTAMP()) .build(); .field(NAME, Types.STRING()) .field(COUNT, Types.DECIMAL()) .field(TIME, Types.SQL_TIMESTAMP()) .build() .toRowType() .withSchema( new Schema() .field(FRUIT_NAME, Types.STRING()).from(NAME) .field(COUNT, Types.DECIMAL()) // no from so it must match with the input .field(EVENT_TIME, Types.SQL_TIMESTAMP()).rowtime( new Rowtime().timestampsFromField(TIME).watermarksPeriodicAscending()) .field(PROC_TIME, Types.SQL_TIMESTAMP()).proctime()) .inAppendMode();
/** * Validates a field of the schema to be the processing time attribute. * * @param proctimeAttribute The name of the field that becomes the processing time field. */ private Optional<String> validateProctimeAttribute(Optional<String> proctimeAttribute) { return proctimeAttribute.map((attribute) -> { // validate that field exists and is of correct type Optional<TypeInformation<?>> tpe = schema.getFieldType(attribute); if (!tpe.isPresent()) { throw new ValidationException("Processing time attribute '" + attribute + "' is not present in TableSchema."); } else if (tpe.get() != Types.SQL_TIMESTAMP()) { throw new ValidationException("Processing time attribute '" + attribute + "' is not of type SQL_TIMESTAMP."); } return attribute; }); }
@Override public TypeInformation<?> getResultType(Class<?>[] signature) { return Types.LONG(); } }
.field(FRUIT_NAME, Types.STRING()) .field(COUNT, Types.DECIMAL()) .field(EVENT_TIME, Types.SQL_TIMESTAMP()) .build(); .withSchema( new Schema() .field(FRUIT_NAME, Types.STRING()) .field(COUNT, Types.DECIMAL()) .field(EVENT_TIME, Types.SQL_TIMESTAMP())) .inAppendMode();
/** * Validates a list of fields to be rowtime attributes. * * @param rowtimeAttributeDescriptors The descriptors of the rowtime attributes. */ private List<RowtimeAttributeDescriptor> validateRowtimeAttributeDescriptors(List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors) { Preconditions.checkNotNull(rowtimeAttributeDescriptors, "List of rowtime attributes must not be null."); // validate that all declared fields exist and are of correct type for (RowtimeAttributeDescriptor desc : rowtimeAttributeDescriptors) { String rowtimeAttribute = desc.getAttributeName(); Optional<TypeInformation<?>> tpe = schema.getFieldType(rowtimeAttribute); if (!tpe.isPresent()) { throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not present in TableSchema."); } else if (tpe.get() != Types.SQL_TIMESTAMP()) { throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not of type SQL_TIMESTAMP."); } } return rowtimeAttributeDescriptors; }
.withSchema( new Schema() .field(FIELD_KEY, Types.LONG()) .field(FIELD_FRUIT_NAME, Types.STRING()) .field(FIELD_COUNT, Types.DECIMAL()) .field(FIELD_TS, Types.SQL_TIMESTAMP())) .inUpsertMode();
/** * Validates a field of the schema to be the processing time attribute. * * @param proctimeAttribute The name of the field that becomes the processing time field. */ private Optional<String> validateProctimeAttribute(Optional<String> proctimeAttribute) { return proctimeAttribute.map((attribute) -> { // validate that field exists and is of correct type Optional<TypeInformation<?>> tpe = schema.getFieldType(attribute); if (!tpe.isPresent()) { throw new ValidationException("Processing time attribute '" + attribute + "' is not present in TableSchema."); } else if (tpe.get() != Types.SQL_TIMESTAMP()) { throw new ValidationException("Processing time attribute '" + attribute + "' is not of type SQL_TIMESTAMP."); } return attribute; }); }
/** * Validates a field of the schema to be the processing time attribute. * * @param proctimeAttribute The name of the field that becomes the processing time field. */ private Optional<String> validateProctimeAttribute(Optional<String> proctimeAttribute) { return proctimeAttribute.map((attribute) -> { // validate that field exists and is of correct type Optional<TypeInformation<?>> tpe = schema.getFieldType(attribute); if (!tpe.isPresent()) { throw new ValidationException("Processing time attribute '" + attribute + "' is not present in TableSchema."); } else if (tpe.get() != Types.SQL_TIMESTAMP()) { throw new ValidationException("Processing time attribute '" + attribute + "' is not of type SQL_TIMESTAMP."); } return attribute; }); }
/** * Validates a list of fields to be rowtime attributes. * * @param rowtimeAttributeDescriptors The descriptors of the rowtime attributes. */ private List<RowtimeAttributeDescriptor> validateRowtimeAttributeDescriptors(List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors) { Preconditions.checkNotNull(rowtimeAttributeDescriptors, "List of rowtime attributes must not be null."); // validate that all declared fields exist and are of correct type for (RowtimeAttributeDescriptor desc : rowtimeAttributeDescriptors) { String rowtimeAttribute = desc.getAttributeName(); Optional<TypeInformation<?>> tpe = schema.getFieldType(rowtimeAttribute); if (!tpe.isPresent()) { throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not present in TableSchema."); } else if (tpe.get() != Types.SQL_TIMESTAMP()) { throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not of type SQL_TIMESTAMP."); } } return rowtimeAttributeDescriptors; }
/** * Validates a list of fields to be rowtime attributes. * * @param rowtimeAttributeDescriptors The descriptors of the rowtime attributes. */ private List<RowtimeAttributeDescriptor> validateRowtimeAttributeDescriptors(List<RowtimeAttributeDescriptor> rowtimeAttributeDescriptors) { Preconditions.checkNotNull(rowtimeAttributeDescriptors, "List of rowtime attributes must not be null."); // validate that all declared fields exist and are of correct type for (RowtimeAttributeDescriptor desc : rowtimeAttributeDescriptors) { String rowtimeAttribute = desc.getAttributeName(); Optional<TypeInformation<?>> tpe = schema.getFieldType(rowtimeAttribute); if (!tpe.isPresent()) { throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not present in TableSchema."); } else if (tpe.get() != Types.SQL_TIMESTAMP()) { throw new ValidationException("Rowtime attribute '" + rowtimeAttribute + "' is not of type SQL_TIMESTAMP."); } } return rowtimeAttributeDescriptors; }