static final <X extends Value> TypeInformation<X> getValueTypeInfo(Class<X> typeClass) { if (Value.class.isAssignableFrom(typeClass) && !typeClass.equals(Value.class)) { return new ValueTypeInfo<X>(typeClass); } else { throw new InvalidTypesException("The given class is no subclass of " + Value.class.getName()); } } }
@Override @SuppressWarnings("unchecked") public TypeSerializer<T> createSerializer() { if (CopyableValue.class.isAssignableFrom(type)) { return (TypeSerializer<T>) createCopyableValueSerializer(type.asSubclass(CopyableValue.class)); } else { return new ValueSerializer<T>(type); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public TypeComparator<T> createComparator(boolean sortOrderAscending) { if (!isKeyType()) { throw new RuntimeException("The type " + type.getName() + " is not Comparable."); } if (CopyableValue.class.isAssignableFrom(type)) { return (TypeComparator<T>) new ValueComparator(sortOrderAscending, type); } else { return (TypeComparator<T>) new CopyableValueComparator(sortOrderAscending, type); } }
if (!((ValueTypeInfo<?>) typeInfo).equals(actual = ValueTypeInfo.getValueTypeInfo((Class<? extends Value>) type))) { throw new InvalidTypesException("Value type '" + typeInfo + "' expected but was '" + actual + "'.");
return (TypeInformation<X>) ValueTypeInfo.getValueTypeInfo(valueClass);
clazz = Class.forName(VALUE_PACKAGE + "." + className + "Value"); returnType = ValueTypeInfo.getValueTypeInfo((Class<Value>) clazz);
/** * Creates a DataSet that represents the Strings produced by reading the given file line wise. * This method is similar to {@link #readTextFile(String)}, but it produces a DataSet with mutable * {@link StringValue} objects, rather than Java Strings. StringValues can be used to tune implementations * to be less object and garbage collection heavy. * <p> * The file will be read with the system's default character set. * * @param filePath The path of the file, as a URI (e.g., "file:///some/local/file" or "hdfs://host:port/file/path"). * @return A DataSet that represents the data read from the given file as text lines. */ public DataSource<StringValue> readTextFileWithValue(String filePath) { Validate.notNull(filePath, "The file path may not be null."); return new DataSource<StringValue>(this, new TextValueInputFormat(new Path(filePath)), new ValueTypeInfo<StringValue>(StringValue.class) ); }
/** * Creates a DataSet that represents the Strings produced by reading the given file line wise. * This method is similar to {@link #readTextFile(String, String)}, but it produces a DataSet with mutable * {@link StringValue} objects, rather than Java Strings. StringValues can be used to tune implementations * to be less object and garbage collection heavy. * <p> * The {@link java.nio.charset.Charset} with the given name will be used to read the files. * * @param filePath The path of the file, as a URI (e.g., "file:///some/local/file" or "hdfs://host:port/file/path"). * @param charsetName The name of the character set used to read the file. * @param skipInvalidLines A flag to indicate whether to skip lines that cannot be read with the given character set. * * @return A DataSet that represents the data read from the given file as text lines. */ public DataSource<StringValue> readTextFileWithValue(String filePath, String charsetName, boolean skipInvalidLines) { Validate.notNull(filePath, "The file path may not be null."); TextValueInputFormat format = new TextValueInputFormat(new Path(filePath)); format.setCharsetName(charsetName); format.setSkipInvalidLines(skipInvalidLines); return new DataSource<StringValue>(this, format, new ValueTypeInfo<StringValue>(StringValue.class) ); }