Search in sources :

Example 1 with VoltTableRow

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

the class Client method runStatusLoop.

/**
     * Loop until all auctions have closed, printing status for each auction at
     * specific intervals.
     */
static void runStatusLoop() {
    // create a second client handle for this second thread
    org.voltdb.client.Client client = null;
    try {
        ClientConfig config = new ClientConfig("program", "pass");
        client = ClientFactory.createClient(config);
        client.createConnection("localhost");
    } catch (java.io.IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    boolean auctionsOver = false;
    while (auctionsOver == false) {
        try {
            // assume auctions have ended. if any open auctions are found, then set this false
            auctionsOver = true;
            // print out the status header
            System.out.printf("\nAUCTION STATUS AS OF: %tT\n", new Date());
            System.out.printf("+-----------------------------------------------------" + "-----------------------------------------------+\n");
            System.out.printf("| %-20s | %-16s | %-16s | %5s | %8s | %9s | %-6s |\n", "ITEM", "BIDDER", "SELLER", "BIDS", "PRICE", "END", "STATUS");
            System.out.printf("+-----------------------------------------------------" + "-----------------------------------------------+\n");
            // loop over all auction ids, printing a row of status for each one
            for (int auctionId : allAuctionIds) {
                VoltTable[] statusResultSet = client.callProcedure("AuctionStatus", auctionId).getResults();
                if (statusResultSet.length != 1)
                    throw new Exception("AuctionStatus returned no results");
                VoltTable statusTable = statusResultSet[0];
                VoltTableRow row = statusTable.fetchRow(0);
                System.out.printf("| %-20s | %-16s | %-16s | %5d | %8.2f | %9tT | %-6s |\n", row.getString("item"), row.getString("bidder"), row.getString("seller"), row.getLong("bidcount"), row.getDouble("price"), row.getTimestampAsTimestamp("endtime").asApproximateJavaDate(), row.getString("status"));
                if (row.getString("status").equals("OPEN"))
                    auctionsOver = false;
            }
            // print the status footer
            System.out.printf("+-----------------------------------------------------" + "-----------------------------------------------+\n");
            // wait for next status update
            Thread.sleep(1000 * statusPeriodInSeconds);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    try {
        client.close();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : VoltTable(org.voltdb.VoltTable) Date(java.util.Date) ClientConfig(org.voltdb.client.ClientConfig) VoltTableRow(org.voltdb.VoltTableRow)

Example 2 with VoltTableRow

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

the class BeginCall method run.

/**
     * Procedure main logic.
     *
     * @param uuid Column value for tuple insertion and partitioning key for this procedure.
     * @param val Column value for tuple insertion.
     * @param update_ts Column value for tuple insertion.
     * @param newestToDiscard Try to remove any tuples as old or older than this value.
     * @param targetMaxRowsToDelete The upper limit on the number of rows to delete per transaction.
     * @return The number of deleted rows.
     * @throws VoltAbortException on bad input.
    */
public long run(int agent_id, String phone_no, long call_id, TimestampType start_ts) {
    voltQueueSQL(findOpenCall, EXPECT_ZERO_OR_ONE_ROW, call_id, agent_id, phone_no);
    voltQueueSQL(findCompletedCall, EXPECT_ZERO_OR_ONE_ROW, call_id, agent_id, phone_no);
    VoltTable[] results = voltExecuteSQL();
    boolean completedCall = results[1].getRowCount() > 0;
    if (completedCall) {
        return -1;
    }
    VoltTable openRowTable = results[0];
    if (openRowTable.getRowCount() > 0) {
        VoltTableRow existingCall = openRowTable.fetchRow(0);
        // check if this is the second begin we've seen for this open call
        existingCall.getTimestampAsTimestamp("start_ts");
        if (existingCall.wasNull() == false) {
            return -1;
        }
        // check if this completes the call
        TimestampType end_ts = existingCall.getTimestampAsTimestamp("end_ts");
        if (existingCall.wasNull() == false) {
            int durationms = (int) ((end_ts.getTime() - start_ts.getTime()) / 1000);
            // update per-day running stddev calculation
            computeRunningStdDev(agent_id, end_ts, durationms);
            // completes the call
            voltQueueSQL(deleteOpenCall, EXPECT_SCALAR_MATCH(1), call_id, agent_id, phone_no);
            voltQueueSQL(insertCompletedCall, EXPECT_SCALAR_MATCH(1), call_id, agent_id, phone_no, start_ts, end_ts, durationms);
            voltExecuteSQL(true);
            return 0;
        }
    }
    voltQueueSQL(upsertOpenCall, EXPECT_SCALAR_MATCH(1), call_id, agent_id, phone_no, start_ts);
    voltExecuteSQL(true);
    return 0;
}
Also used : TimestampType(org.voltdb.types.TimestampType) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 3 with VoltTableRow

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

the class BeginOrEndCallBase method computeRunningStdDev.

void computeRunningStdDev(int agent_id, TimestampType end_ts, long durationms) {
    voltQueueSQL(findTodaysStddevStatsForAgent, EXPECT_ZERO_OR_ONE_ROW, end_ts, agent_id);
    VoltTable stddevTable = voltExecuteSQL()[0];
    long nprev = 0, n = 0;
    long sumprev = 0, sum = 0;
    double qprev = 0, q = 0;
    double avgprev = 0, avg = 0;
    double stddev = 0;
    if (stddevTable.getRowCount() == 1) {
        VoltTableRow stddevRow = stddevTable.fetchRow(0);
        nprev = stddevRow.getLong("n");
        sumprev = stddevRow.getLong("sumk");
        qprev = stddevRow.getDouble("qk");
    }
    n = nprev + 1;
    sum = sumprev + durationms;
    avgprev = nprev > 0 ? (sumprev / (double) nprev) : 0;
    avg = sum / (double) n;
    q = qprev + (durationms - avgprev) * (durationms - avg);
    stddev = Math.sqrt(q / n);
    // really basic validity checks that the math hasn't corrupted something
    if (!Double.isFinite(q)) {
        throw new VoltAbortException("q is not finite");
    }
    if (!Double.isFinite(avg)) {
        throw new VoltAbortException("avg is not finite");
    }
    if (!Double.isFinite(stddev)) {
        throw new VoltAbortException("stddev is not finite");
    }
    voltQueueSQL(upsertTodaysStddevStatsForAgent, EXPECT_SCALAR_MATCH(1), agent_id, end_ts, n, sum, q, stddev);
}
Also used : VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 4 with VoltTableRow

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

the class TrackEvent method run.

public long run(TimestampType utc_time, long ip_address, long cookie_uid, int creative_id, int inventory_id, int type_id, BigDecimal cost) throws VoltAbortException {
    // derive counter fields from type_id
    //   0 = impression
    //   1 = clickthrough
    //   2 = conversion
    int is_impression = (type_id == 0) ? 1 : 0;
    int is_clickthrough = (type_id == 1) ? 1 : 0;
    int is_conversion = (type_id == 2) ? 1 : 0;
    // lookup creative_id and inventory_id
    voltQueueSQL(selectCreative, creative_id);
    voltQueueSQL(selectInventory, inventory_id);
    VoltTable[] lookups = voltExecuteSQL();
    VoltTableRow creative = lookups[0].fetchRow(0);
    int campaign_id = (int) creative.getLong(0);
    int advertiser_id = (int) creative.getLong(1);
    VoltTableRow inventory = lookups[1].fetchRow(0);
    int site_id = (int) inventory.getLong(0);
    int page_id = (int) inventory.getLong(1);
    voltQueueSQL(insertEvent, utc_time, ip_address, cookie_uid, creative_id, inventory_id, type_id, cost, campaign_id, advertiser_id, site_id, page_id, is_impression, is_clickthrough, is_conversion);
    voltExecuteSQL();
    return ClientResponse.SUCCESS;
}
Also used : VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 5 with VoltTableRow

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

the class AuctionStatus method run.

/**
     * Get a tuple of useful status info about an auction.
     *
     * @param itemId The id of the item we'd like to know about.
     * @return A table with one row and fields:
     *  (item, bidder, seller, bidcount, price, endtime, status)
     * @throws VoltAbortException Currently doesn't abort.
     */
public VoltTable[] run(int itemId) throws VoltAbortException {
    // create a new VoltTable to store our results
    VoltTable retval = new VoltTable(new VoltTable.ColumnInfo("item", VoltType.STRING), new VoltTable.ColumnInfo("bidder", VoltType.STRING), new VoltTable.ColumnInfo("seller", VoltType.STRING), new VoltTable.ColumnInfo("bidcount", VoltType.BIGINT), new VoltTable.ColumnInfo("price", VoltType.FLOAT), new VoltTable.ColumnInfo("endtime", VoltType.TIMESTAMP), new VoltTable.ColumnInfo("status", VoltType.STRING));
    // get the seller id and item name from ITEM table
    voltQueueSQL(getItemInfo, itemId);
    VoltTable itemTable = voltExecuteSQL()[0];
    VoltTableRow itemRow = itemTable.fetchRow(0);
    // resulting info:
    long sellerId = itemRow.getLong("SELLERID");
    String itemName = itemRow.getString("ITEMNAME");
    long endTime = itemRow.getTimestampAsLong("ENDTIME");
    long highBidId = itemRow.getLong("HIGHBIDID");
    // get high bid info
    voltQueueSQL(getBidInfo, highBidId);
    VoltTable statusTable = voltExecuteSQL()[0];
    VoltTableRow row = statusTable.fetchRow(0);
    // resulting info:
    long bidderId = row.getLong("BIDDERID");
    double bidPrice = row.getDouble("BIDPRICE");
    // count the number of bids on the auction
    voltQueueSQL(getBidCount, itemId);
    VoltTable bidCountTable = voltExecuteSQL()[0];
    VoltTableRow bidCountRow = bidCountTable.fetchRow(0);
    // resulting info:
    // the minus one is for the fake initial bid
    long bidCount = bidCountRow.getLong(0) - 1;
    // get the names of the bidder and seller
    voltQueueSQL(getUserName, sellerId);
    if (bidderId >= 0) {
        voltQueueSQL(getUserName, bidderId);
    }
    VoltTable[] nameTables = voltExecuteSQL();
    VoltTableRow sellerNameRow = nameTables[0].fetchRow(0);
    // we should always have a seller name
    String sellerName = sellerNameRow.getString("FIRSTNAME") + " " + sellerNameRow.getString("LASTNAME");
    // we might not always have a bidder name, so need this if statement
    String bidderName = "NO BIDDER";
    if (bidderId >= 0) {
        VoltTableRow bidderNameRow = nameTables[1].fetchRow(0);
        bidderName = bidderNameRow.getString("FIRSTNAME") + " " + bidderNameRow.getString("LASTNAME");
    }
    // check the timing and set the auction status accordingly
    String status = "OPEN";
    long now = new TimestampType().getTime();
    if (endTime < now)
        status = "CLOSED";
    // add the single tuple to our return table
    retval.addRow(itemName, bidderName, sellerName, bidCount, bidPrice, endTime, status);
    return new VoltTable[] { retval };
}
Also used : TimestampType(org.voltdb.types.TimestampType) 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