Search in sources :

Example 1 with ConfigOption

use of org.apache.flink.configuration.ConfigOption in project flink by apache.

the class ConfigOptionsDocGenerator method extractConfigOptions.

@VisibleForTesting
static List<OptionWithMetaInfo> extractConfigOptions(Class<?> clazz) {
    try {
        List<OptionWithMetaInfo> configOptions = new ArrayList<>(8);
        Field[] fields = clazz.getFields();
        for (Field field : fields) {
            if (isConfigOption(field) && shouldBeDocumented(field)) {
                configOptions.add(new OptionWithMetaInfo((ConfigOption<?>) field.get(null), field));
            }
        }
        return configOptions;
    } catch (Exception e) {
        throw new RuntimeException("Failed to extract config options from class " + clazz + '.', e);
    }
}
Also used : ConfigOption(org.apache.flink.configuration.ConfigOption) Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) IOException(java.io.IOException) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 2 with ConfigOption

use of org.apache.flink.configuration.ConfigOption in project flink by apache.

the class DataGenTableSourceFactory method createDynamicTableSource.

@Override
public DynamicTableSource createDynamicTableSource(Context context) {
    Configuration options = new Configuration();
    context.getCatalogTable().getOptions().forEach(options::setString);
    DataType rowDataType = context.getPhysicalRowDataType();
    DataGenerator<?>[] fieldGenerators = new DataGenerator[DataType.getFieldCount(rowDataType)];
    Set<ConfigOption<?>> optionalOptions = new HashSet<>();
    List<String> fieldNames = DataType.getFieldNames(rowDataType);
    List<DataType> fieldDataTypes = DataType.getFieldDataTypes(rowDataType);
    for (int i = 0; i < fieldGenerators.length; i++) {
        String name = fieldNames.get(i);
        DataType type = fieldDataTypes.get(i);
        ConfigOption<String> kind = key(DataGenConnectorOptionsUtil.FIELDS + "." + name + "." + DataGenConnectorOptionsUtil.KIND).stringType().defaultValue(DataGenConnectorOptionsUtil.RANDOM);
        DataGeneratorContainer container = createContainer(name, type, options.get(kind), options);
        fieldGenerators[i] = container.getGenerator();
        optionalOptions.add(kind);
        optionalOptions.addAll(container.getOptions());
    }
    FactoryUtil.validateFactoryOptions(requiredOptions(), optionalOptions, options);
    Set<String> consumedOptionKeys = new HashSet<>();
    consumedOptionKeys.add(CONNECTOR.key());
    consumedOptionKeys.add(DataGenConnectorOptions.ROWS_PER_SECOND.key());
    consumedOptionKeys.add(DataGenConnectorOptions.NUMBER_OF_ROWS.key());
    optionalOptions.stream().map(ConfigOption::key).forEach(consumedOptionKeys::add);
    FactoryUtil.validateUnconsumedKeys(factoryIdentifier(), options.keySet(), consumedOptionKeys);
    String name = context.getObjectIdentifier().toString();
    return new DataGenTableSource(fieldGenerators, name, rowDataType, options.get(DataGenConnectorOptions.ROWS_PER_SECOND), options.get(DataGenConnectorOptions.NUMBER_OF_ROWS));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ConfigOption(org.apache.flink.configuration.ConfigOption) DataGenerator(org.apache.flink.streaming.api.functions.source.datagen.DataGenerator) DataType(org.apache.flink.table.types.DataType) HashSet(java.util.HashSet)

Example 3 with ConfigOption

use of org.apache.flink.configuration.ConfigOption in project flink by apache.

the class RandomGeneratorVisitor method visit.

@Override
public DataGeneratorContainer visit(RowType rowType) {
    List<DataGeneratorContainer> fieldContainers = rowType.getFields().stream().map(field -> {
        String fieldName = name + "." + field.getName();
        return field.getType().accept(new RandomGeneratorVisitor(fieldName, config));
    }).collect(Collectors.toList());
    ConfigOption<?>[] options = fieldContainers.stream().flatMap(container -> container.getOptions().stream()).toArray(ConfigOption[]::new);
    DataGenerator[] generators = fieldContainers.stream().map(DataGeneratorContainer::getGenerator).toArray(DataGenerator[]::new);
    return DataGeneratorContainer.of(new RowDataGenerator(generators, rowType.getFieldNames()), options);
}
Also used : ConfigOptions(org.apache.flink.configuration.ConfigOptions) GenericArrayData(org.apache.flink.table.data.GenericArrayData) TinyIntType(org.apache.flink.table.types.logical.TinyIntType) IntType(org.apache.flink.table.types.logical.IntType) FloatType(org.apache.flink.table.types.logical.FloatType) MapType(org.apache.flink.table.types.logical.MapType) RowType(org.apache.flink.table.types.logical.RowType) CharType(org.apache.flink.table.types.logical.CharType) TimestampType(org.apache.flink.table.types.logical.TimestampType) DecimalType(org.apache.flink.table.types.logical.DecimalType) DoubleType(org.apache.flink.table.types.logical.DoubleType) ReadableConfig(org.apache.flink.configuration.ReadableConfig) BooleanType(org.apache.flink.table.types.logical.BooleanType) RowDataGenerator(org.apache.flink.connector.datagen.table.types.RowDataGenerator) DecimalDataRandomGenerator(org.apache.flink.connector.datagen.table.types.DecimalDataRandomGenerator) GenericMapData(org.apache.flink.table.data.GenericMapData) Duration(java.time.Duration) Map(java.util.Map) DataGeneratorMapper(org.apache.flink.connector.datagen.table.types.DataGeneratorMapper) RandomGenerator(org.apache.flink.streaming.api.functions.source.datagen.RandomGenerator) ConfigOption(org.apache.flink.configuration.ConfigOption) YearMonthIntervalType(org.apache.flink.table.types.logical.YearMonthIntervalType) MultisetType(org.apache.flink.table.types.logical.MultisetType) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) DataGenerator(org.apache.flink.streaming.api.functions.source.datagen.DataGenerator) TimestampData(org.apache.flink.table.data.TimestampData) ConfigOptions.key(org.apache.flink.configuration.ConfigOptions.key) BigIntType(org.apache.flink.table.types.logical.BigIntType) DayTimeIntervalType(org.apache.flink.table.types.logical.DayTimeIntervalType) Set(java.util.Set) VarCharType(org.apache.flink.table.types.logical.VarCharType) ArrayType(org.apache.flink.table.types.logical.ArrayType) Collectors(java.util.stream.Collectors) SmallIntType(org.apache.flink.table.types.logical.SmallIntType) StringData(org.apache.flink.table.data.StringData) List(java.util.List) LogicalType(org.apache.flink.table.types.logical.LogicalType) ValidationException(org.apache.flink.table.api.ValidationException) Internal(org.apache.flink.annotation.Internal) ZonedTimestampType(org.apache.flink.table.types.logical.ZonedTimestampType) ConfigOption(org.apache.flink.configuration.ConfigOption) RowDataGenerator(org.apache.flink.connector.datagen.table.types.RowDataGenerator) DataGenerator(org.apache.flink.streaming.api.functions.source.datagen.DataGenerator) RowDataGenerator(org.apache.flink.connector.datagen.table.types.RowDataGenerator)

Example 4 with ConfigOption

use of org.apache.flink.configuration.ConfigOption in project zeppelin by apache.

the class Flink113Shims method extractConfigOptions.

private Map<String, ConfigOption> extractConfigOptions(Class clazz) {
    Map<String, ConfigOption> configOptions = new HashMap();
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        if (field.getType().isAssignableFrom(ConfigOption.class)) {
            try {
                ConfigOption configOption = (ConfigOption) field.get(ConfigOption.class);
                configOptions.put(configOption.key(), configOption);
            } catch (Throwable e) {
                LOGGER.warn("Fail to get ConfigOption", e);
            }
        }
    }
    return configOptions;
}
Also used : ConfigOption(org.apache.flink.configuration.ConfigOption) Field(java.lang.reflect.Field) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AttributedString(org.jline.utils.AttributedString)

Example 5 with ConfigOption

use of org.apache.flink.configuration.ConfigOption in project flink by apache.

the class JdbcDynamicTableFactory method checkAllOrNone.

private void checkAllOrNone(ReadableConfig config, ConfigOption<?>[] configOptions) {
    int presentCount = 0;
    for (ConfigOption configOption : configOptions) {
        if (config.getOptional(configOption).isPresent()) {
            presentCount++;
        }
    }
    String[] propertyNames = Arrays.stream(configOptions).map(ConfigOption::key).toArray(String[]::new);
    Preconditions.checkArgument(configOptions.length == presentCount || presentCount == 0, "Either all or none of the following options should be provided:\n" + String.join("\n", propertyNames));
}
Also used : ConfigOption(org.apache.flink.configuration.ConfigOption)

Aggregations

ConfigOption (org.apache.flink.configuration.ConfigOption)10 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Configuration (org.apache.flink.configuration.Configuration)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 DataGenerator (org.apache.flink.streaming.api.functions.source.datagen.DataGenerator)2 AttributedString (org.jline.utils.AttributedString)2 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Internal (org.apache.flink.annotation.Internal)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 CPUResource (org.apache.flink.api.common.resources.CPUResource)1 ConfigOptions (org.apache.flink.configuration.ConfigOptions)1 ConfigOptions.key (org.apache.flink.configuration.ConfigOptions.key)1