@Override public void setIsAppendOnly(Boolean isAppendOnly) { if (this.isAppendOnly && !isAppendOnly) { throw new ValidationException( "The given query is not supported by this sink because the sink is configured to " + "operate in append mode only. Thus, it only support insertions (no queries " + "with updating results)."); } }
/** * Validates that the given key is not included in these properties. */ public void validateExclusion(String key) { if (properties.containsKey(key)) { throw new ValidationException("Property '" + key + "' is not allowed in this context."); } }
public static Class<?> loadClass(String qualifiedName, ClassLoader classLoader) { try { return Class.forName(qualifiedName, true, classLoader); } catch (Exception e) { throw new ValidationException("Class '" + qualifiedName + "' could not be loaded. " + "Please note that inner classes must be globally accessible and declared static.", e); } }
private void validateOptional(String key, boolean isOptional, Consumer<String> valueValidation) { if (!properties.containsKey(key)) { if (!isOptional) { throw new ValidationException("Could not find required property '" + key + "'."); } } else { final String value = properties.get(key); valueValidation.accept(value); } }
private void put(String key, String value) { if (properties.containsKey(key)) { throw new ValidationException("Property already present: " + key); } if (normalizeKeys) { properties.put(key.toLowerCase(), value); } else { properties.put(key, value); } }
/** * Validates that the given prefix is not included in these properties. */ public void validatePrefixExclusion(String prefix) { properties.keySet().stream() .filter(k -> k.startsWith(prefix)) .findFirst() .ifPresent((k) -> { throw new ValidationException( "Properties with prefix '" + prefix + "' are not allowed in this context. " + "But property '" + k + "' was found."); }); }
/** * Returns a byte value under the given key if it exists. */ public Optional<Byte> getOptionalByte(String key) { return optionalGet(key).map((value) -> { try { return Byte.valueOf(value); } catch (Exception e) { throw new ValidationException("Invalid byte value for key '" + key + "'.", e); } }); }
/** * Returns a boolean value under the given key if it exists. */ public Optional<Boolean> getOptionalBoolean(String key) { return optionalGet(key).map((value) -> { try { return Boolean.valueOf(value); } catch (Exception e) { throw new ValidationException("Invalid boolean value for key '" + key + "'.", e); } }); }
/** * Returns an integer value under the given key if it exists. */ public Optional<Integer> getOptionalInt(String key) { return optionalGet(key).map((value) -> { try { return Integer.valueOf(value); } catch (Exception e) { throw new ValidationException("Invalid integer value for key '" + key + "'.", e); } }); }
/** * Returns a long value under the given key if it exists. */ public Optional<Long> getOptionalLong(String key) { return optionalGet(key).map((value) -> { try { return Long.valueOf(value); } catch (Exception e) { throw new ValidationException("Invalid long value for key '" + key + "'.", e); } }); }
/** * Returns a short value under the given key if it exists. */ public Optional<Short> getOptionalShort(String key) { return optionalGet(key).map((value) -> { try { return Short.valueOf(value); } catch (Exception e) { throw new ValidationException("Invalid short value for key '" + key + "'.", e); } }); }
public static String encodeObjectToString(Serializable obj) { try { final byte[] bytes = InstantiationUtil.serializeObject(obj); return new String(BASE64_ENCODER.encode(bytes), UTF_8); } catch (Exception e) { throw new ValidationException( "Unable to serialize object '" + obj.toString() + "' of class '" + obj.getClass().getName() + "'."); } }
/** * Returns a character value under the given key if it exists. */ public Optional<Character> getOptionalCharacter(String key) { return optionalGet(key).map((c) -> { if (c.length() != 1) { throw new ValidationException("The value of '" + key + "' must only contain one character."); } return c.charAt(0); }); }
/** * Returns a big decimal value under the given key if it exists. */ public Optional<BigDecimal> getOptionalBigDecimal(String key) { return optionalGet(key).map((value) -> { try { return new BigDecimal(value); } catch (Exception e) { throw new ValidationException("Invalid decimal value for key '" + key + "'.", e); } }); }
/** * Returns a double value under the given key if it exists. */ public Optional<Double> getOptionalDouble(String key) { return optionalGet(key).map((value) -> { try { return Double.valueOf(value); } catch (Exception e) { throw new ValidationException("Invalid double value for key '" + key + "'.", e); } }); }
/** * Returns a float value under the given key if it exists. */ public Optional<Float> getOptionalFloat(String key) { return optionalGet(key).map((value) -> { try { return Float.valueOf(value); } catch (Exception e) { throw new ValidationException("Invalid float value for key '" + key + "'.", e); } }); }
private ValidationException parsingError(String cause) { throw new ValidationException("Could not parse type information at position " + lastCursor() + ": " + cause + "\n" + "Input type string: " + inputString); }
/** * Returns a Flink {@link MemorySize} under the given key if it exists. */ public Optional<MemorySize> getOptionalMemorySize(String key) { return optionalGet(key).map((value) -> { try { return MemorySize.parse(value, MemorySize.MemoryUnit.BYTES); } catch (Exception e) { throw new ValidationException("Invalid memory size value for key '" + key + "'.", e); } }); }
@Override public KafkaTableSinkBase configure(String[] fieldNames, TypeInformation<?>[] fieldTypes) { if (!Arrays.equals(getFieldNames(), fieldNames) || !Arrays.equals(getFieldTypes(), fieldTypes)) { throw new ValidationException("Reconfiguration with different fields is not allowed. " + "Expected: " + Arrays.toString(getFieldNames()) + " / " + Arrays.toString(getFieldTypes()) + ". " + "But was: " + Arrays.toString(fieldNames) + " / " + Arrays.toString(fieldTypes)); } return this; }
/** * Adds a class under the given key. */ public void putClass(String key, Class<?> clazz) { checkNotNull(key); checkNotNull(clazz); final String error = InstantiationUtil.checkForInstantiationError(clazz); if (error != null) { throw new ValidationException("Class '" + clazz.getName() + "' is not supported: " + error); } put(key, clazz.getName()); }