Configuration conf = new Configuration(); conf.set("fs.defaultFS", "hdfs://localhost:9000"); TableSchema schema = new Schema( Optional.of(1), new SchemaField("id", Types.IntegerType.get()), new SchemaField("name", Types.StringType.get()) ); Table table = new HadoopTables(conf).create(schema, "hdfs://localhost:9000/data/my_table"); table.newAppend() .appendFile(Paths.get("hdfs://localhost:9000/data/data.csv")) .commit(); table.updateSpec() .addFieldPartitionStrategy("name", "hash", 4) .commit(); table.newRewrite() .rewriteDataFiles() .clusterBy("id") .build(); Iterable<Row> rows = table.newScan() .filter(Expressions.equal("name", "John")) .select("id", "name") .execute(); for (Row row : rows) { System.out.println(row); }


上一篇:
下一篇:
切换中文