/** * Creates a request to read an entire table. */ public static Request createTableScanRequest(String table) { TPlanRequestParams request = new TPlanRequestParams(); request.request_type = TRequestType.Sql; request.sql_stmt = "SELECT * FROM " + table; return new Request(request); }
/** * Sets the field delimiter for a path request. Invalid for non-path requests. */ public Request setFieldDelimiter(char delimiter) { verifyPathRequest("setFieldDelimiter()"); request_.path.setField_delimiter((byte)delimiter); return this; }
request = Request.createTableScanRequest(tblName); } else { List<String> projection = new ArrayList<String>(); request = Request.createProjectionRequest(tblName, projection); "Only reading a single directory is currently supported."); request = Request.createPathRequest(inputDir); } else if (sqlQuery != null) { request = Request.createSqlRequest(sqlQuery); } else { Preconditions.checkState(false);
public static void main(String[] args) throws RecordServiceException, IOException { String query = "select * from tpch.nation"; if (args.length == 2) query = args[1]; PlanRequestResult plan = new RecordServicePlannerClient.Builder() .planRequest(PLANNER_HOST, PLANNER_PORT, Request.createSqlRequest(query)); Schema avroSchema = SchemaUtils.convertSchema(plan.schema); System.out.println("Avro Schema:\n" + avroSchema); System.out.println("Records:"); for (int t = 0; t < plan.tasks.size(); ++t) { GenericRecords records = null; try { records = new GenericRecords(WorkerClientUtil.execTask(plan, t)); while (records.hasNext()) { GenericData.Record record = records.next(); System.out.println(record); } } finally { if (records != null) records.close(); } } } }
/** * Creates a request that is a SQL query. */ public static Request createSqlRequest(String query) { TPlanRequestParams request = new TPlanRequestParams(); request.request_type = TRequestType.Sql; request.sql_stmt = query; return new Request(request); }
/** * Sets a query for a path request. Invalid for non-path requests. */ public Request setQuery(String query) { verifyPathRequest("setQuery()"); request_.path.setQuery(query); return this; }
/** * Creates a request to read a projection of a table. An empty or null * projection returns the number of rows in the table (as a BIGINT). */ public static Request createProjectionRequest(String table, List<String> cols) { TPlanRequestParams request = new TPlanRequestParams(); request.request_type = TRequestType.Sql; if (cols == null || cols.size() == 0) { request.sql_stmt = "SELECT count(*) FROM " + table; } else { StringBuilder sb = new StringBuilder("SELECT "); for (int i = 0; i < cols.size(); ++i) { if (i != 0) sb.append(", "); sb.append(cols.get(i)); } sb.append(" FROM ").append(table); request.sql_stmt = sb.toString(); } return new Request(request); }
/** * Sets the schema for a path request. Invalid for non-path requests. */ public Request setSchema(Schema schema) { verifyPathRequest("setSchema()"); request_.path.setSchema(schema.toThrift()); return this; }
/** * Creates a request that is a PATH query. This does a full scan of the * data files in 'uri'. */ public static Request createPathRequest(String uri) { TPlanRequestParams request = new TPlanRequestParams(); request.request_type = TRequestType.Path; request.path = new TPathRequest(uri); return new Request(request); }