private Supplier<TableException> exceptionSupplier(String key) { return () -> { throw new TableException( "Property with key '" + key + "' could not be found. " + "This is a bug because the validation logic should have checked that before."); }; }
@Override public void setIsAppendOnly(Boolean isAppendOnly) { if (this.isAppendOnly && !isAppendOnly) { throw new ValidationException( "The given query is not supported by this sink because the sink is configured to " + "operate in append mode only. Thus, it only support insertions (no queries " + "with updating results)."); } }
@Override public TableSchema getTableSchema() { return new TableSchema( new String[] {"key", "rowtime", "payload"}, new TypeInformation[] {Types.INT, Types.SQL_TIMESTAMP, Types.STRING}); }
private static TableSchema removeTimeAttributes(TableSchema schema) { final TableSchema.Builder builder = TableSchema.builder(); for (int i = 0; i < schema.getFieldCount(); i++) { final TypeInformation<?> type = schema.getFieldTypes()[i]; final TypeInformation<?> convertedType; if (FlinkTypeFactory.isTimeIndicatorType(type)) { convertedType = Types.SQL_TIMESTAMP; } else { convertedType = type; } builder.field(schema.getFieldNames()[i], convertedType); } return builder.build(); } }
/** * 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 String[] getFieldNames() { return schema.getFieldNames(); }
@Override public TypeInformation<?>[] getFieldTypes() { return schema.getFieldTypes(); }
@Override public TypeInformation<Row> getRecordType() { return schema.toRowType(); }
public static Builder builder() { return new Builder(); }
/** * Creates a table using the given query in the given table environment. */ private Table createTable(TableEnvironment tableEnv, String selectQuery) { // parse and validate query try { return tableEnv.sqlQuery(selectQuery); } catch (Throwable t) { // catch everything such that the query does not crash the executor throw new SqlExecutionException("Invalid SQL statement.", t); } }
/** * Validates that the given key is not included in these properties. */ public void validateExclusion(String key) { if (properties.containsKey(key)) { throw new ValidationException("Property '" + key + "' is not allowed in this context."); } }
/** * Returns a {@link TableSchema} instance. */ public TableSchema build() { return new TableSchema( fieldNames.toArray(new String[0]), fieldTypes.toArray(new TypeInformation<?>[0])); } }
@Override public String[] getFieldNames() { return schema.getFieldNames(); }
@Override public TypeInformation<?>[] getFieldTypes() { return schema.getFieldTypes(); }
@Override public TypeInformation<Row> getOutputType() { return schema.toRowType(); }
public static Class<?> loadClass(String qualifiedName, ClassLoader classLoader) { try { return Class.forName(qualifiedName, true, classLoader); } catch (Exception e) { throw new ValidationException("Class '" + qualifiedName + "' could not be loaded. " + "Please note that inner classes must be globally accessible and declared static.", e); } }
@Override public TableSchema getTableSchema() { if (this.tableSchema == null) { return new TableSchema(getFieldNames(), getFieldTypes()); } else { return this.tableSchema; } }
/** * @deprecated Use {@link TableSchema#getFieldNames()} instead. Can be dropped after 1.7. */ @Deprecated public String[] getColumnNames() { return getFieldNames(); }
/** * @deprecated Use {@link TableSchema#getFieldTypes()} instead. Can be dropped after 1.7. */ @Deprecated public TypeInformation<?>[] getTypes() { return getFieldTypes(); }