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()); } } }
/** * 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) ); }