use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class AliasOperationUtils method createAliasList.
/**
* Creates a list of valid alias expressions. Resulting expression might still contain {@link
* UnresolvedReferenceExpression}.
*
* @param aliases aliases to validate
* @param child relational operation on top of which to apply the aliases
* @return validated list of aliases
*/
static List<Expression> createAliasList(List<Expression> aliases, QueryOperation child) {
ResolvedSchema childSchema = child.getResolvedSchema();
if (aliases.size() > childSchema.getColumnCount()) {
throw new ValidationException("Aliasing more fields than we actually have.");
}
List<ValueLiteralExpression> fieldAliases = aliases.stream().map(f -> f.accept(aliasLiteralValidator)).collect(Collectors.toList());
List<String> childNames = childSchema.getColumnNames();
return IntStream.range(0, childNames.size()).mapToObj(idx -> {
UnresolvedReferenceExpression oldField = unresolvedRef(childNames.get(idx));
if (idx < fieldAliases.size()) {
ValueLiteralExpression alias = fieldAliases.get(idx);
return unresolvedCall(BuiltInFunctionDefinitions.AS, oldField, alias);
} else {
return oldField;
}
}).collect(Collectors.toList());
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class TestValuesTableFactory method validateAndExtractRowtimeIndex.
private static int validateAndExtractRowtimeIndex(CatalogTable sinkTable, boolean dropLateEvent, boolean isInsertOnly) {
if (!dropLateEvent) {
return -1;
} else if (!isInsertOnly) {
throw new ValidationException("Option 'sink.drop-late-event' only works for insert-only sink now.");
}
TableSchema schema = sinkTable.getSchema();
List<WatermarkSpec> watermarkSpecs = schema.getWatermarkSpecs();
if (watermarkSpecs.size() == 0) {
throw new ValidationException("Please define the watermark in the schema that is used to indicate the rowtime column. " + "The sink function will compare the rowtime and the current watermark to determine whether the event is late.");
}
String rowtimeName = watermarkSpecs.get(0).getRowtimeAttribute();
return Arrays.asList(schema.getFieldNames()).indexOf(rowtimeName);
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class OperationConverterUtils method convertChangeColumn.
public static Operation convertChangeColumn(ObjectIdentifier tableIdentifier, SqlChangeColumn changeColumn, CatalogTable catalogTable, SqlValidator sqlValidator) {
String oldName = changeColumn.getOldName().getSimple();
if (catalogTable.getPartitionKeys().indexOf(oldName) >= 0) {
// disallow changing partition columns
throw new ValidationException("CHANGE COLUMN cannot be applied to partition columns");
}
TableSchema oldSchema = catalogTable.getSchema();
boolean first = changeColumn.isFirst();
String after = changeColumn.getAfter() == null ? null : changeColumn.getAfter().getSimple();
TableColumn newTableColumn = toTableColumn(changeColumn.getNewColumn(), sqlValidator);
TableSchema newSchema = changeColumn(oldSchema, oldName, newTableColumn, first, after);
Map<String, String> newProperties = new HashMap<>(catalogTable.getOptions());
newProperties.putAll(extractProperties(changeColumn.getProperties()));
return new AlterTableSchemaOperation(tableIdentifier, new CatalogTableImpl(newSchema, catalogTable.getPartitionKeys(), newProperties, catalogTable.getComment()));
// TODO: handle watermark and constraints
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class FileSystemTableFactoryTest method testUnsupportedOptionSink.
@Test
public void testUnsupportedOptionSink() {
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "filesystem");
descriptor.putString("path", "/tmp");
descriptor.putString("format", "csv");
descriptor.putString("my_option", "my");
try {
createTableSink(SCHEMA, descriptor.asMap());
} catch (ValidationException e) {
Throwable cause = e.getCause();
assertTrue(cause.toString(), cause instanceof ValidationException);
assertTrue(cause.getMessage(), cause.getMessage().contains("Unsupported options:\n\nmy_option"));
return;
}
fail("Should fail by ValidationException.");
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class FileSystemTableFactoryTest method testUnsupportedOptionSource.
@Test
public void testUnsupportedOptionSource() {
DescriptorProperties descriptor = new DescriptorProperties();
descriptor.putString(FactoryUtil.CONNECTOR.key(), "filesystem");
descriptor.putString("path", "/tmp");
descriptor.putString("format", "csv");
descriptor.putString("my_option", "my");
try {
createTableSource(SCHEMA, descriptor.asMap());
} catch (ValidationException e) {
Throwable cause = e.getCause();
assertTrue(cause.toString(), cause instanceof ValidationException);
assertTrue(cause.getMessage(), cause.getMessage().contains("Unsupported options:\n\nmy_option"));
return;
}
fail("Should fail by ValidationException.");
}
Aggregations