Search in sources :

Example 56 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class TestSQLTypesSuite method testInsertMinValues_No_Nulls.

//
// Round trip the minimum value.
//
public void testInsertMinValues_No_Nulls() throws NoConnectionsException, ProcCallException, IOException {
    final Client client = this.getClient();
    // Insert a MIN value for each column. For the first
    // row, insert null in the first column, for the 5th row
    // in the 5 column, etc.
    final Object[] params = new Object[COLS + 2];
    for (int k = 0; k < COLS; ++k) {
        // build the parameter list as described above
        params[0] = "";
        params[1] = pkey.incrementAndGet();
        for (int i = 0; i < COLS; i++) {
            params[i + 2] = (i == k) ? m_minValues[i] : m_midValues[i];
            assert (params[i + 2] != null);
        }
        // Perform the inserts and execute selects, verifying the
        // content of the select matches the parameters passed to
        // insert
        System.out.println("testInsertMinValues: " + k + " MIN type is " + m_types[k]);
        params[0] = "NO_NULLS";
        client.callProcedure("Insert", params);
        final VoltTable[] result = client.callProcedure("Select", "NO_NULLS", pkey.get()).getResults();
        final VoltTableRow row = result[0].fetchRow(0);
        for (int i = 0; i < COLS; ++i) {
            final Object obj = row.get(i + 1, m_types[i]);
            assertTrue(!row.wasNull());
            assertTrue(comparisonHelper(obj, params[i + 2], m_types[i]));
        }
    }
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 57 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class TestSQLTypesSuite method testInsertNulls_Nulls_Allowed.

//
// Verify that NULLS are allowed in non-NOT NULL columns
//
public void testInsertNulls_Nulls_Allowed() throws IOException {
    final Client client = this.getClient();
    // Insert a NULL value for each column. For the first
    // row, insert null in the first column, for the 5th row
    // in the 5 column, etc.
    final Object[] params = new Object[COLS + 2];
    for (int k = 0; k < COLS; ++k) {
        // build the parameter list as described above
        params[0] = "";
        params[1] = pkey.incrementAndGet();
        for (int i = 0; i < COLS; i++) {
            params[i + 2] = (i == k) ? m_nullValues[i] : m_midValues[i];
            assert (params[i + 2] != null);
        }
        // Each insert in to the ALLOW_NULLS table must succeed.
        // Perform the inserts and execute selects, verifying the
        // content of the select matches the parameters passed to
        // insert
        System.out.println("testNullsAllowed: " + k + " NULL type is " + m_types[k]);
        try {
            params[0] = "ALLOW_NULLS";
            // We'll use the multi-partition insert for this test. Between
            // this and testInsertNull_No_Nulls we should cover both
            // cases in ticket 306
            client.callProcedure("InsertMulti", params);
        } catch (final ProcCallException e) {
            e.printStackTrace();
            fail();
        } catch (final NoConnectionsException e) {
            e.printStackTrace();
            fail();
        }
        // verify that the row was inserted
        try {
            final VoltTable[] result = client.callProcedure("Select", "ALLOW_NULLS", pkey.get()).getResults();
            final VoltTableRow row = result[0].fetchRow(0);
            for (int i = 0; i < COLS; ++i) {
                final Object obj = row.get(i + 1, m_types[i]);
                if (i == k) {
                    assertTrue(row.wasNull());
                    System.out.println("Row " + i + " verifed as NULL");
                } else {
                    assertTrue(comparisonHelper(obj, params[i + 2], m_types[i]));
                }
            }
        } catch (final Exception ex) {
            ex.printStackTrace();
            fail();
        }
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) ProcCallException(org.voltdb.client.ProcCallException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 58 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class ClientMover method main.

public static void main(String[] args) {
    long numMoves = (long) Long.valueOf(args[0]);
    String serverList = args[1];
    long clientDurationSeconds = (long) Long.valueOf(args[2]);
    long loopPauseSeconds = (long) Long.valueOf(args[3]);
    m_logger.info(String.format("Executing %,d moves per transaction", numMoves));
    m_logger.info(String.format("Running for %,d second(s)", clientDurationSeconds));
    int num_partitions = 0;
    long playerId;
    long gameId;
    long socialId;
    long clientId;
    long visitTime;
    int intCounter;
    long longCounter;
    final org.voltdb.client.Client voltclient = ClientFactory.createClient();
    String[] voltServers = serverList.split(",");
    for (String thisServer : voltServers) {
        try {
            thisServer = thisServer.trim();
            m_logger.info(String.format("Connecting to server: %s", thisServer));
            voltclient.createConnection(thisServer, "program", "none");
        } catch (IOException e) {
            m_logger.error(e.toString());
            System.exit(-1);
        }
    }
    java.util.Random rand = new java.util.Random(0);
    long startTime = System.currentTimeMillis();
    long endTime = startTime + (1000l * clientDurationSeconds);
    long currentTime = startTime;
    // get the # of partitions in my cluster
    try {
        VoltTable[] vtPartitionInfo = voltclient.callProcedure("@Statistics", "partitioncount", 0l).getResults();
        num_partitions = (int) vtPartitionInfo[0].fetchRow(0).getLong(0);
        m_logger.info("System is running with " + num_partitions + " partition(s).");
    } catch (ProcCallException e) {
        m_logger.error("ProcCallException:");
        m_logger.error(e.toString());
    } catch (IOException e) {
        m_logger.error("IOException:");
        m_logger.error(e.toString());
        System.exit(-1);
    }
    boolean foundRows = true;
    boolean foundFullRowset = false;
    while (endTime > currentTime) {
        // do a single archive at each partition
        foundRows = false;
        foundFullRowset = false;
        long callTimeMillis = System.currentTimeMillis();
        FileOutputStream fout;
        try {
            String outFileName = "/tmp/" + callTimeMillis + "_rows.txt";
            fout = new FileOutputStream(outFileName, true);
            for (longCounter = 0; longCounter < num_partitions; longCounter++) {
                try {
                    long callTimeBegin = System.currentTimeMillis();
                    VoltTable[] vtArchiveVisits = voltclient.callProcedure("ArchiveVisits", longCounter, numMoves, callTimeMillis).getResults();
                    long callTimeEnd = System.currentTimeMillis();
                    int rowCount = vtArchiveVisits[0].getRowCount();
                    if (rowCount > 0) {
                        // write out the rows
                        foundRows = true;
                        if (rowCount == numMoves) {
                            foundFullRowset = true;
                        }
                        // write out the rows
                        for (intCounter = 0; intCounter < rowCount; intCounter++) {
                            VoltTableRow row = vtArchiveVisits[0].fetchRow(intCounter);
                            playerId = row.getLong(0);
                            gameId = row.getLong(1);
                            socialId = row.getLong(2);
                            clientId = row.getLong(3);
                            visitTime = row.getLong(4);
                            Date visitDate = new Date(visitTime);
                            new PrintStream(fout).print(playerId + "\t" + gameId + "\t" + socialId + "\t" + clientId + "\t" + visitDate + "\n");
                        }
                    }
                    String currentDate = new Date().toString();
                    m_logger.info(String.format("[%s] Ran archive on partition %d : archived %,d row(s) in %,d milliseconds", currentDate, longCounter, rowCount, (callTimeEnd - callTimeBegin)));
                } catch (ProcCallException e) {
                    m_logger.error("ProcCallException:");
                    m_logger.error(e.toString());
                } catch (NoConnectionsException e) {
                    m_logger.error("IOException:");
                    m_logger.error(e.toString());
                    System.exit(-1);
                }
            }
            fout.close();
            if (!foundRows) {
                // no rows found, delete file
                boolean success = (new File(outFileName)).delete();
                if (success) {
                    m_logger.info("No rows found for this run, deleted " + outFileName);
                } else {
                    m_logger.info("No rows found for this run, BUT unable to delete " + outFileName);
                }
                // pause for 5 seconds
                m_logger.info(String.format("Pausing for %d seconds...", loopPauseSeconds));
                long pauseCurrentMillis = System.currentTimeMillis();
                long pauseEndMillis = pauseCurrentMillis + (loopPauseSeconds * 1000l);
                while (pauseCurrentMillis < pauseEndMillis) {
                    pauseCurrentMillis = System.currentTimeMillis();
                }
            } else if (!foundFullRowset) {
                // none of the rowsets were full (amount requested)
                // pause for given number seconds
                m_logger.info(String.format("No full rowsets found, pausing for %d seconds...", loopPauseSeconds));
                long pauseCurrentMillis = System.currentTimeMillis();
                long pauseEndMillis = pauseCurrentMillis + (loopPauseSeconds * 1000l);
                while (pauseCurrentMillis < pauseEndMillis) {
                    pauseCurrentMillis = System.currentTimeMillis();
                }
            }
        } catch (IOException e) {
            m_logger.error(e.toString());
            System.exit(-1);
        }
        currentTime = System.currentTimeMillis();
    }
    try {
        voltclient.drain();
    } catch (InterruptedException e) {
        m_logger.error(e.toString());
        System.exit(-1);
    } catch (NoConnectionsException e) {
        m_logger.error(e.toString());
        System.exit(-1);
    }
    try {
        voltclient.close();
    } catch (Exception e) {
        m_logger.error(e.toString());
        System.exit(-1);
    }
}
Also used : PrintStream(java.io.PrintStream) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) Date(java.util.Date) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) NoConnectionsException(org.voltdb.client.NoConnectionsException) FileOutputStream(java.io.FileOutputStream) VoltTableRow(org.voltdb.VoltTableRow) File(java.io.File) ProcCallException(org.voltdb.client.ProcCallException)

Example 59 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class paymentByCustomerName method run.

public VoltTable[] run(short w_id, byte d_id, double h_amount, short c_w_id, byte c_d_id, String c_last, TimestampType timestamp) throws VoltAbortException {
    voltQueueSQL(getCustomersByLastName, c_last, c_d_id, c_w_id);
    final VoltTable customers = voltExecuteSQL()[0];
    final int namecnt = customers.getRowCount();
    if (namecnt == 0) {
        throw new VoltAbortException("no customers with last name: " + c_last + " in warehouse: " + c_w_id + " and in district " + c_d_id);
    }
    final int index = (namecnt - 1) / 2;
    final VoltTableRow customer = customers.fetchRow(index);
    final int c_id = (int) customer.getLong(C_ID_IDX);
    return processPayment(w_id, d_id, c_w_id, c_d_id, c_id, h_amount, customer, timestamp);
}
Also used : VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 60 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class TestMaterializedViewSuite method subtestUpdateSinglePartition.

private void subtestUpdateSinglePartition() throws IOException, ProcCallException {
    Client client = getClient();
    truncateBeforeTest(client);
    VoltTable[] results = null;
    results = client.callProcedure("AggAges", 1).getResults();
    assertEquals(1, results.length);
    assertEquals(0, results[0].getRowCount());
    assert (results != null);
    results = client.callProcedure("AddPerson", 1, 1L, 31L, 27500.20, 7, NORMALLY).getResults();
    assertEquals(1, results.length);
    assertEquals(1L, results[0].asScalarLong());
    results = client.callProcedure("AddPerson", 1, 2L, 31L, 28920.99, 3, NORMALLY).getResults();
    assertEquals(1, results.length);
    assertEquals(1L, results[0].asScalarLong());
    results = client.callProcedure("AddPerson", 1, 3L, 33L, 28920.99, 3, NORMALLY).getResults();
    assertEquals(1, results.length);
    assertEquals(1L, results[0].asScalarLong());
    results = client.callProcedure("UpdatePerson", 1, 2L, 31L, 15000.00, 3).getResults();
    assertEquals(1, results.length);
    assertEquals(1L, results[0].asScalarLong());
    results = client.callProcedure("UpdatePerson", 1, 1L, 31L, 15000.00, 5).getResults();
    assertEquals(1, results.length);
    assertEquals(1L, results[0].asScalarLong());
    results = client.callProcedure("AggAges", 1).getResults();
    assert (results != null);
    assertEquals(1, results.length);
    assertEquals(2, results[0].getRowCount());
    System.out.println(results[0].toString());
    VoltTableRow r1 = results[0].fetchRow(0);
    VoltTableRow r2 = results[0].fetchRow(1);
    assertEquals(31L, r1.getLong(0));
    assertEquals(2L, r1.getLong(2));
    assertTrue(Math.abs(r1.getDouble(3) - 30000.0) < .01);
    assertEquals(8L, r1.getLong(4));
    assertEquals(33L, r2.getLong(0));
    assertEquals(1L, r2.getLong(2));
    assertTrue(Math.abs(r2.getDouble(3) - 28920.99) < .01);
    assertEquals(3L, r2.getLong(4));
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Aggregations

VoltTableRow (org.voltdb.VoltTableRow)65 VoltTable (org.voltdb.VoltTable)57 Client (org.voltdb.client.Client)23 ProcCallException (org.voltdb.client.ProcCallException)11 TimestampType (org.voltdb.types.TimestampType)7 NoConnectionsException (org.voltdb.client.NoConnectionsException)6 IOException (java.io.IOException)5 VoltAbortException (org.voltdb.VoltProcedure.VoltAbortException)5 Date (java.util.Date)4 WorkWithBigString (org.voltdb_testprocs.regressionsuites.sqlfeatureprocs.WorkWithBigString)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 ClientResponse (org.voltdb.client.ClientResponse)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 ByteBuilder (org.voltdb.benchmark.tpcc.procedures.ByteBuilder)1