Search in sources :

Example 36 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class DataGenTableSourceFactoryTest method testLackStartForSequence.

@Test
public void testLackStartForSequence() {
    try {
        DescriptorProperties descriptor = new DescriptorProperties();
        descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
        descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND, DataGenConnectorOptionsUtil.SEQUENCE);
        descriptor.putLong(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.END, 100);
        createTableSource(ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())), descriptor.asMap());
    } catch (ValidationException e) {
        Throwable cause = e.getCause();
        Assert.assertTrue(cause.toString(), cause instanceof ValidationException);
        Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Could not find required property 'fields.f0.start' for sequence generator."));
        return;
    }
    Assert.fail("Should fail by ValidationException.");
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) DataGeneratorSourceTest(org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSourceTest) Test(org.junit.Test)

Example 37 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class DataGenTableSourceFactoryTest method testWrongStartInRandom.

@Test
public void testWrongStartInRandom() {
    try {
        DescriptorProperties descriptor = new DescriptorProperties();
        descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
        descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND, DataGenConnectorOptionsUtil.RANDOM);
        descriptor.putLong(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.START, 0);
        createTableSource(ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())), descriptor.asMap());
    } catch (ValidationException e) {
        Throwable cause = e.getCause();
        Assert.assertTrue(cause.toString(), cause instanceof ValidationException);
        Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Unsupported options:\n\nfields.f0.start"));
        return;
    }
    Assert.fail("Should fail by ValidationException.");
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) DataGeneratorSourceTest(org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSourceTest) Test(org.junit.Test)

Example 38 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class DataGenTableSourceFactoryTest method testWrongLenInRandomLong.

@Test
public void testWrongLenInRandomLong() {
    try {
        DescriptorProperties descriptor = new DescriptorProperties();
        descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
        descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND, DataGenConnectorOptionsUtil.RANDOM);
        descriptor.putInt(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.LENGTH, 100);
        createTableSource(ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())), descriptor.asMap());
    } catch (ValidationException e) {
        Throwable cause = e.getCause();
        Assert.assertTrue(cause.toString(), cause instanceof ValidationException);
        Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Unsupported options:\n\nfields.f0.length"));
        return;
    }
    Assert.fail("Should fail by ValidationException.");
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) DataGeneratorSourceTest(org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSourceTest) Test(org.junit.Test)

Example 39 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class DataGenTableSourceFactoryTest method testWrongTypes.

@Test
public void testWrongTypes() {
    try {
        DescriptorProperties descriptor = new DescriptorProperties();
        descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
        descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND, DataGenConnectorOptionsUtil.SEQUENCE);
        descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.START, "Wrong");
        descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.END, "Wrong");
        createTableSource(ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())), descriptor.asMap());
    } catch (ValidationException e) {
        Throwable cause = e.getCause();
        Assert.assertTrue(cause.toString(), cause instanceof IllegalArgumentException);
        Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Could not parse value 'Wrong' for key 'fields.f0.start'"));
        return;
    }
    Assert.fail("Should fail by ValidationException.");
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) DataGeneratorSourceTest(org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSourceTest) Test(org.junit.Test)

Example 40 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class TableImpl method select.

@Override
public Table select(Expression... fields) {
    List<Expression> expressionsWithResolvedCalls = preprocessExpressions(fields);
    CategorizedExpressions extracted = OperationExpressionsUtils.extractAggregationsAndProperties(expressionsWithResolvedCalls);
    if (!extracted.getWindowProperties().isEmpty()) {
        throw new ValidationException("Window properties can only be used on windowed tables.");
    }
    if (!extracted.getAggregations().isEmpty()) {
        QueryOperation aggregate = operationTreeBuilder.aggregate(Collections.emptyList(), extracted.getAggregations(), operationTree);
        return createTable(operationTreeBuilder.project(extracted.getProjections(), aggregate, false));
    } else {
        return createTable(operationTreeBuilder.project(expressionsWithResolvedCalls, operationTree, false));
    }
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression) Expression(org.apache.flink.table.expressions.Expression) CategorizedExpressions(org.apache.flink.table.operations.utils.OperationExpressionsUtils.CategorizedExpressions) QueryOperation(org.apache.flink.table.operations.QueryOperation)

Aggregations

ValidationException (org.apache.flink.table.api.ValidationException)143 DataType (org.apache.flink.table.types.DataType)25 Test (org.junit.Test)23 HashMap (java.util.HashMap)21 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)19 LogicalType (org.apache.flink.table.types.logical.LogicalType)18 TableException (org.apache.flink.table.api.TableException)17 List (java.util.List)14 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)14 QueryOperation (org.apache.flink.table.operations.QueryOperation)14 LinkedHashMap (java.util.LinkedHashMap)13 DescriptorProperties (org.apache.flink.table.descriptors.DescriptorProperties)13 CatalogTable (org.apache.flink.table.catalog.CatalogTable)12 Expression (org.apache.flink.table.expressions.Expression)12 TableSchema (org.apache.flink.table.api.TableSchema)11 Catalog (org.apache.flink.table.catalog.Catalog)11 ContextResolvedTable (org.apache.flink.table.catalog.ContextResolvedTable)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Internal (org.apache.flink.annotation.Internal)10