/** * Create a prepared statement for a query that joins two tables and has ORDER BY clause. */ @Test public void joinOrderByQuery() throws Exception { String query = "SELECT l.l_quantity, l.l_shipdate, o.o_custkey FROM cp.\"tpch/lineitem.parquet\" l JOIN cp.\"tpch/orders.parquet\" o " + "ON l.l_orderkey = o.o_orderkey LIMIT 2"; PreparedStatement preparedStatement = createPrepareStmt(query, false, null); List<ExpectedColumnResult> expMetadata = ImmutableList.of( new ExpectedColumnResult("l_quantity", "DOUBLE", true, 24, 0, 0, true, Double.class.getName()), new ExpectedColumnResult("l_shipdate", "DATE", true, 10, 0, 0, false, Date.class.getName()), new ExpectedColumnResult("o_custkey", "INTEGER", true, 11, 0, 0, true, Integer.class.getName()) ); verifyMetadata(expMetadata, preparedStatement.getColumnsList()); }
/** * Simple query. * @throws Exception */ @Test public void simple() throws Exception { String query = "SELECT * FROM cp.\"region.json\" ORDER BY region_id LIMIT 1"; PreparedStatement preparedStatement = createPrepareStmt(query, false, null); List<ExpectedColumnResult> expMetadata = ImmutableList.of( new ExpectedColumnResult("region_id", "BIGINT", true, 20, 0, 0, true, Long.class.getName()), new ExpectedColumnResult("sales_city", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("sales_state_province", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("sales_district", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("sales_region", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("sales_country", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("sales_district_id", "BIGINT", true, 20, 0, 0, true, Long.class.getName()) ); verifyMetadata(expMetadata, preparedStatement.getColumnsList()); testBuilder() .unOrdered() .preparedStatement(preparedStatement.getServerHandle()) .baselineColumns("region_id", "sales_city", "sales_state_province", "sales_district", "sales_region", "sales_country", "sales_district_id") .baselineValues(0L, "None", "None", "No District", "No Region", "No Country", 0L) .go(); }
/** * Create a prepared statement for a query that has GROUP BY clause in it */ @Test public void groupByQuery() throws Exception { String query = "SELECT sales_city, count(*) as cnt FROM cp.\"region.json\" " + "GROUP BY sales_city ORDER BY sales_city DESC LIMIT 1"; PreparedStatement preparedStatement = createPrepareStmt(query, false, null); List<ExpectedColumnResult> expMetadata = ImmutableList.of( new ExpectedColumnResult("sales_city", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("cnt", "BIGINT", true, 20, 0, 0, true, Long.class.getName()) ); verifyMetadata(expMetadata, preparedStatement.getColumnsList()); testBuilder() .unOrdered() .preparedStatement(preparedStatement.getServerHandle()) .baselineColumns("sales_city", "cnt") .baselineValues("Yakima", 1L) .go(); }
protected DremioPreparedStatementImpl(DremioConnectionImpl connection, StatementHandle h, Meta.Signature signature, PreparedStatement preparedStatementHandle, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { super(connection, h, signature, resultSetType, resultSetConcurrency, resultSetHoldability); connection.openStatementsRegistry.addStatement(this); this.preparedStatementHandle = preparedStatementHandle; if (preparedStatementHandle != null) { ((DremioColumnMetaDataList) signature.columns).updateColumnMetaData(preparedStatementHandle.getColumnsList()); } }
public void writeTo(io.protostuff.Output output, com.dremio.exec.proto.UserProtos.PreparedStatement message) throws java.io.IOException { for(com.dremio.exec.proto.UserProtos.ResultColumnMetadata columns : message.getColumnsList()) output.writeObject(1, columns, com.dremio.exec.proto.SchemaUserProtos.ResultColumnMetadata.WRITE, true); if(message.hasServerHandle()) output.writeObject(2, message.getServerHandle(), com.dremio.exec.proto.SchemaUserProtos.PreparedStatementHandle.WRITE, false); } public boolean isInitialized(com.dremio.exec.proto.UserProtos.PreparedStatement message)