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);
}
}
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));
}
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);
}
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;
}
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));
}
Aggregations