public void testUpdateLogging() throws Exception { Client client = getClient(); VoltTable results[] = null; results = client.callProcedure("@UpdateLogging", m_loggingConfig).getResults(); for (VoltTable result : results) { assertEquals(0, result.asScalarLong()); } }
/** Count the number of tuples in the table. */ static long tupleCount(VoltTable t) throws Exception { if (t == null) { return 0; } VoltTable result = client.callProcedure( "@AdHoc", String.format("select count(*) from %s;", TableHelper.getTableName(t))) .getResults()[0]; return result.asScalarLong(); }
/** Find the largest pkey value in the table. */ static long maxId(VoltTable t) throws Exception { if (t == null) { return 0; } VoltTable result = client.callProcedure( "@AdHoc", String.format( "select pkey from %s order by pkey desc limit 1;", TableHelper.getTableName(t))) .getResults()[0]; return result.getRowCount() > 0 ? result.asScalarLong() : 0; }
public static void doTestJoinAndLimitOffset(Client client) throws IOException, ProcCallException, InterruptedException { int limits[] = new int[] {1, 2, 5, 10, 12, 25, Integer.MAX_VALUE}; int offsets[] = new int[] {0, 1, 2, 5, 10, 12, 25}; String selecteds[] = new String[] {"*", "A.PKEY"}; String joinops[] = new String[] {",", "LEFT JOIN", "RIGHT JOIN"}; String conditions[] = new String[] {" A.PKEY < B.PKEY ", " A.PKEY = B.PKEY ", " A.I = B.I "}; client.callProcedure("InsertA", -1, 0); for (String joinop : joinops) { String onwhere = "ON"; if (joinop.equals(",")) { onwhere = "WHERE"; } for (String selected : selecteds) { for (int limit : limits) { for (int offset : offsets) { for (String condition : conditions) { String query; VoltTable result; query = "SELECT COUNT(*) FROM A " + joinop + " B " + onwhere + condition + ";"; result = client.callProcedure("@AdHoc", query).getResults()[0]; long found = result.asScalarLong(); query = "SELECT " + selected + " FROM A " + joinop + " B " + onwhere + condition + " ORDER BY A.PKEY, B.PKEY " + ((limit == Integer.MAX_VALUE) ? "" : "LIMIT " + limit) + ((offset == 0) ? "" : " OFFSET " + offset) + ";"; result = client.callProcedure("@AdHoc", query).getResults()[0]; long expectedRowCount = Math.max(0, Math.min(limit, found - offset)); assertEquals( "Statement \"" + query + "\" produced wrong number of rows: ", expectedRowCount, result.getRowCount()); } } } } } }
long getRowCount() throws NoConnectionsException, IOException, ProcCallException { VoltTable t = client.callProcedure("@AdHoc", "select count(*) from " + tableName + ";").getResults()[0]; return t.asScalarLong(); }
public VoltTable run(short w_id, int o_carrier_id, TimestampType timestamp) throws VoltAbortException { for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) { voltQueueSQL(getNewOrder, d_id, w_id); } final VoltTable[] neworderresults = voltExecuteSQL(); assert neworderresults.length == Constants.DISTRICTS_PER_WAREHOUSE; final Long[] no_o_ids = new Long[Constants.DISTRICTS_PER_WAREHOUSE]; int valid_neworders = 0; int[] result_offsets = new int[Constants.DISTRICTS_PER_WAREHOUSE]; for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) { final VoltTable newOrder = neworderresults[(int) d_id - 1]; if (newOrder.getRowCount() == 0) { // No orders for this district: skip it. Note: This must be reported if > 1% result_offsets[(int) d_id - 1] = -1; continue; } assert newOrder.getRowCount() == 1; result_offsets[(int) d_id - 1] = valid_neworders * 2; ++valid_neworders; final Long no_o_id = newOrder.asScalarLong(); no_o_ids[(int) d_id - 1] = no_o_id; voltQueueSQL(getCId, no_o_id, d_id, w_id); voltQueueSQL(sumOLAmount, no_o_id, d_id, w_id); } final VoltTable[] otherresults = voltExecuteSQL(); assert otherresults.length == valid_neworders * 2; for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) { final VoltTable newOrder = neworderresults[(int) d_id - 1]; if (newOrder.getRowCount() == 0) { // No orders for this district: skip it. Note: This must be reported if > 1% continue; } assert newOrder.getRowCount() == 1; final Long no_o_id = newOrder.asScalarLong(); no_o_ids[(int) d_id - 1] = no_o_id; voltQueueSQL(deleteNewOrder, d_id, w_id, no_o_id); voltQueueSQL(updateOrders, o_carrier_id, no_o_id, d_id, w_id); voltQueueSQL(updateOrderLine, timestamp, no_o_id, d_id, w_id); } voltExecuteSQL(); // these must be logged in the "result file" according to TPC-C 2.7.2.2 (page 39) // We remove the queued time, completed time, w_id, and o_carrier_id: the client can figure // them out final VoltTable result = result_template.clone(1024); for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) { int resultoffset = result_offsets[(int) d_id - 1]; if (resultoffset < 0) { continue; } assert otherresults[resultoffset + 0].getRowCount() == 1; assert otherresults[resultoffset + 1].getRowCount() == 1; final long c_id = (otherresults[resultoffset + 0].asScalarLong()); final VoltTableRow row = otherresults[resultoffset + 1].fetchRow(0); final double ol_total = row.getDouble(0); final boolean ol_total_wasnull = row.wasNull(); // If there are no order lines, SUM returns null. There should always be order lines. if (ol_total_wasnull) { throw new VoltAbortException( "ol_total is NULL: there are no order lines. This should not happen"); } assert ol_total > 0.0; voltQueueSQL(updateCustomer, ol_total, c_id, d_id, w_id); final Long no_o_id = no_o_ids[(int) d_id - 1]; result.addRow(d_id, no_o_id); } voltExecuteSQL(); return result; }