use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class DefaultSchemaResolver method resolveWatermarkSpecs.
private List<WatermarkSpec> resolveWatermarkSpecs(List<UnresolvedWatermarkSpec> unresolvedWatermarkSpecs, List<Column> inputColumns) {
if (unresolvedWatermarkSpecs.size() == 0) {
return Collections.emptyList();
}
if (unresolvedWatermarkSpecs.size() > 1) {
throw new ValidationException("Multiple watermark definitions are not supported yet.");
}
final UnresolvedWatermarkSpec watermarkSpec = unresolvedWatermarkSpecs.get(0);
// validate time attribute
final String timeColumn = watermarkSpec.getColumnName();
final Column validatedTimeColumn = validateTimeColumn(timeColumn, inputColumns);
// resolve watermark expression
final ResolvedExpression watermarkExpression;
try {
watermarkExpression = resolveExpression(inputColumns, watermarkSpec.getWatermarkExpression(), validatedTimeColumn.getDataType());
} catch (Exception e) {
throw new ValidationException(String.format("Invalid expression for watermark '%s'.", watermarkSpec.toString()), e);
}
final LogicalType outputType = watermarkExpression.getOutputDataType().getLogicalType();
final LogicalType timeColumnType = validatedTimeColumn.getDataType().getLogicalType();
validateWatermarkExpression(outputType);
if (outputType.getTypeRoot() != timeColumnType.getTypeRoot()) {
throw new ValidationException(String.format("The watermark declaration's output data type '%s' is different " + "from the time field's data type '%s'.", outputType, timeColumnType));
}
return Collections.singletonList(WatermarkSpec.of(watermarkSpec.getColumnName(), watermarkExpression));
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class DefaultSchemaResolver method validateTimeColumn.
private Column validateTimeColumn(String columnName, List<Column> columns) {
final Optional<Column> timeColumn = columns.stream().filter(c -> c.getName().equals(columnName)).findFirst();
if (!timeColumn.isPresent()) {
throw new ValidationException(String.format("Invalid column name '%s' for rowtime attribute in watermark declaration. Available columns are: %s", columnName, columns.stream().map(Column::getName).collect(Collectors.toList())));
}
final LogicalType timeFieldType = timeColumn.get().getDataType().getLogicalType();
if (!canBeTimeAttributeType(timeFieldType) || getPrecision(timeFieldType) > 3) {
throw new ValidationException(String.format("Invalid data type of time field for watermark definition. " + "The field must be of type TIMESTAMP(p) or TIMESTAMP_LTZ(p)," + " the supported precision 'p' is from 0 to 3, but the time field type is %s", timeFieldType));
}
if (isProctimeAttribute(timeFieldType)) {
throw new ValidationException("A watermark can not be defined for a processing-time attribute.");
}
return timeColumn.get();
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class FunctionCatalog method dropTempCatalogFunction.
/**
* Drop a temporary catalog function.
*
* @param identifier identifier of the function
* @param ignoreIfNotExist Flag to specify behavior when the function does not exist: if set to
* false, throw an exception, if set to true, do nothing.
* @return the removed catalog function, which is null if function doesn't exist and
* ignoreIfNotExist is true.
*/
public CatalogFunction dropTempCatalogFunction(ObjectIdentifier identifier, boolean ignoreIfNotExist) {
ObjectIdentifier normalizedName = FunctionIdentifier.normalizeObjectIdentifier(identifier);
CatalogFunction fd = tempCatalogFunctions.get(normalizedName);
if (fd != null) {
catalogManager.getTemporaryOperationListener(normalizedName).ifPresent(l -> l.onDropTemporaryFunction(normalizedName.toObjectPath()));
tempCatalogFunctions.remove(normalizedName);
} else if (!ignoreIfNotExist) {
throw new ValidationException(String.format("Temporary catalog function %s doesn't exist", identifier));
}
return fd;
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class FunctionCatalog method dropCatalogFunction.
/**
* Drops a catalog function by also considering temporary catalog functions. Returns true if a
* function was dropped.
*/
public boolean dropCatalogFunction(UnresolvedIdentifier unresolvedIdentifier, boolean ignoreIfNotExist) {
final ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
final ObjectIdentifier normalizedIdentifier = FunctionIdentifier.normalizeObjectIdentifier(identifier);
final Catalog catalog = catalogManager.getCatalog(normalizedIdentifier.getCatalogName()).orElseThrow(IllegalStateException::new);
final ObjectPath path = identifier.toObjectPath();
// we force users to deal with temporary catalog functions first
if (tempCatalogFunctions.containsKey(normalizedIdentifier)) {
throw new ValidationException(String.format("Could not drop catalog function. A temporary function '%s' does already exist. " + "Please drop the temporary function first.", identifier.asSummaryString()));
}
if (!catalog.functionExists(path)) {
if (ignoreIfNotExist) {
return false;
}
throw new ValidationException(String.format("Could not drop catalog function. A function '%s' doesn't exist.", identifier.asSummaryString()));
}
try {
catalog.dropFunction(path, ignoreIfNotExist);
} catch (Throwable t) {
throw new TableException(String.format("Could not drop catalog function '%s'.", identifier.asSummaryString()), t);
}
return true;
}
use of org.apache.flink.table.api.ValidationException in project flink by apache.
the class FunctionCatalog method registerCatalogFunction.
/**
* Registers a catalog function by also considering temporary catalog functions.
*/
public void registerCatalogFunction(UnresolvedIdentifier unresolvedIdentifier, Class<? extends UserDefinedFunction> functionClass, boolean ignoreIfExists) {
final ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
final ObjectIdentifier normalizedIdentifier = FunctionIdentifier.normalizeObjectIdentifier(identifier);
try {
UserDefinedFunctionHelper.validateClass(functionClass);
} catch (Throwable t) {
throw new ValidationException(String.format("Could not register catalog function '%s' due to implementation errors.", identifier.asSummaryString()), t);
}
final Catalog catalog = catalogManager.getCatalog(normalizedIdentifier.getCatalogName()).orElseThrow(IllegalStateException::new);
final ObjectPath path = identifier.toObjectPath();
// we force users to deal with temporary catalog functions first
if (tempCatalogFunctions.containsKey(normalizedIdentifier)) {
if (ignoreIfExists) {
return;
}
throw new ValidationException(String.format("Could not register catalog function. A temporary function '%s' does already exist. " + "Please drop the temporary function first.", identifier.asSummaryString()));
}
if (catalog.functionExists(path)) {
if (ignoreIfExists) {
return;
}
throw new ValidationException(String.format("Could not register catalog function. A function '%s' does already exist.", identifier.asSummaryString()));
}
final CatalogFunction catalogFunction = new CatalogFunctionImpl(functionClass.getName(), FunctionLanguage.JAVA);
try {
catalog.createFunction(path, catalogFunction, ignoreIfExists);
} catch (Throwable t) {
throw new TableException(String.format("Could not register catalog function '%s'.", identifier.asSummaryString()), t);
}
}
Aggregations