Example #1
0
  @Test
  public void testTimestampStringRoundTrip() throws Exception {
    String[] myOptions = {"-f" + path_csv, "--reportdir=" + reportDir, "BLAH"};

    String[] myData = {
      "1,,,,,,,7777-12-25",
      "2,,,,,,,7777-12-25 00:00:00",
      "3,,,,,,,2000-02-03",
      "4,,,,,,,2000-02-03 00:00:00.0",
      "5,,,,,,,2100-04-05",
      "6,,,,,,,2100-04-05 00:00:00.00",
      "7,,,,,,,2012-12-31",
      "8,,,,,,,2012-12-31 00:00:00.000",
      "9,,,,,,,2001-10-25",
      "10,,,,,,,2001-10-25 00:00:00.0000",
    };
    int invalidLineCnt = 0;
    int validLineCnt = myData.length - invalidLineCnt;
    test_Interface(myOptions, myData, invalidLineCnt, validLineCnt);
    VoltTable ts_table =
        client.callProcedure("@AdHoc", "SELECT * FROM BLAH ORDER BY clm_integer;").getResults()[0];
    while (ts_table.advanceRow()) {
      TimestampType ts1 = ts_table.getTimestampAsTimestamp(7);
      if (ts_table.advanceRow()) {
        TimestampType ts2 = ts_table.getTimestampAsTimestamp(7);
        assertEquals(ts1, ts2);
        continue;
      }
    }
  }
Example #2
0
 private void validateRowOfDecimal(VoltTable vt, BigDecimal[] expected) {
   int len = expected.length;
   assertTrue(vt.advanceRow());
   for (int i = 0; i < len; i++) {
     BigDecimal actual = null;
     try {
       actual = vt.getDecimalAsBigDecimal(i);
     } catch (IllegalArgumentException ex) {
       ex.printStackTrace();
       fail();
     }
     if (expected[i] != null) {
       assertNotSame(null, actual);
       assertEquals(expected[i], actual);
     } else {
       if (isHSQL()) {
         // We don't actually use this with
         // HSQL.  So, just assert failure here.
         fail("HSQL is not used to test the Volt DECIMAL type.");
       } else {
         assertTrue(vt.wasNull());
       }
     }
   }
 }
  /** testEvictTuples */
  @Test
  public void testEvictTuples() throws Exception {
    // First load some stuff into the database
    for (String tableName : TARGET_TABLES) {
      this.loadData(this.getTable(tableName));
    }

    // Then make sure that we can evict from each of them
    for (String tableName : TARGET_TABLES) {
      Table catalog_tbl = this.getTable(tableName);
      VoltTable evictResult = this.evictData(catalog_tbl);
      evictResult.advanceRow();

      // Our stats should now come back with at least one block evicted
      VoltTable results[] = this.ee.getStats(SysProcSelector.TABLE, this.locators, false, 0L);
      assertEquals(1, results.length);
      // System.err.println("-------------------------------");
      // System.err.println(VoltTableUtil.format(results));

      while (results[0].advanceRow()) {
        if (results[0].getString("TABLE_NAME").equalsIgnoreCase(catalog_tbl.getName()) == false)
          continue;
        for (String col : statsFields) {
          assertEquals(col, evictResult.getLong(col), results[0].getLong(col));
          if (col == "ANTICACHE_BLOCKS_EVICTED") {
            assertEquals(col, 1, results[0].getLong(col));
          } else {
            assertNotSame(col, 0, results[0].getLong(col));
          }
        } // FOR
      } // WHILE
    } // FOR
  }
Example #4
0
  public VoltTable[] run(int precision, String tag) {
    if (tag == null || tag.length() == 0) {
      voltQueueSQL(resultStmt);
    } else {
      voltQueueSQL(resultByTagStmt, tag);
    }

    VoltTable[] raw = voltExecuteSQL(true);

    if (precision == 1) return raw;

    final VoltTable result =
        new VoltTable(
            new VoltTable.ColumnInfo("lat", VoltType.SMALLINT),
            new VoltTable.ColumnInfo("lon", VoltType.SMALLINT),
            new VoltTable.ColumnInfo("record_count", VoltType.BIGINT),
            new VoltTable.ColumnInfo("tag", VoltType.STRING));

    final HashMap<String, Long> map = new HashMap<String, Long>();
    while (raw[0].advanceRow()) {
      final String key =
          (raw[0].getLong(0) / (long) precision) * (long) precision
              + ":"
              + (raw[0].getLong(1) / (long) precision) * (long) precision;
      if (map.containsKey(key)) map.put(key, (long) map.get(key) + raw[0].getLong(2));
      else map.put(key, raw[0].getLong(2));
    }
    for (String key : map.keySet()) {
      String[] keyParts = key.split(":");
      result.addRow(
          Short.parseShort(keyParts[0]), Short.parseShort(keyParts[1]), (long) map.get(key), tag);
    }
    return new VoltTable[] {result};
  }
  public void testReplicaDependencyWithMismatchedResults() {
    VoltTable.ColumnInfo[] cols2 = {new VoltTable.ColumnInfo("age", VoltType.INTEGER)};

    VoltTable t3 = new VoltTable(cols2, 1);
    t3.addRow(11);

    setUpSites(2, 2, 1);
    int multi_dep = 5 | DtxnConstants.MULTIPARTITION_DEPENDENCY;
    WorkUnit w =
        new WorkUnit(
            m_voltdb.getCatalogContext().siteTracker,
            work,
            new int[] {4, multi_dep},
            0,
            new int[] {1, 2, 3},
            false);
    assertFalse(w.allDependenciesSatisfied());
    assertEquals(w.getDependency(4).size(), 0);
    assertEquals(w.getDependency(5).size(), 0);
    w.putDependency(4, 0, t1);
    assertFalse(w.allDependenciesSatisfied());
    w.putDependency(multi_dep, 0, t2);
    assertFalse(w.allDependenciesSatisfied());
    boolean threw = false;
    try {
      w.putDependency(multi_dep, 1, t3);
    } catch (RuntimeException e) {
      threw = true;
    }
    assertTrue(threw);
  }
  /**
   * add 20 shuffled rows
   *
   * @throws InterruptedException
   */
  private void load(Client client)
      throws NoConnectionsException, ProcCallException, IOException, InterruptedException {
    int pkey = 0;
    a_int.clear();
    a_inline_str.clear();
    a_pool_str.clear();

    boolean async = true;

    for (int i = 0; i < 20; i++) {
      a_int.add(i);
      a_inline_str.add("a_" + i);
      a_pool_str.add(simpleString + i);
    }

    Collections.shuffle(a_int);
    Collections.shuffle(a_inline_str);
    Collections.shuffle(a_pool_str);

    for (int i = 0; i < 20; i++) {
      SyncCallback cb = new SyncCallback();
      client.callProcedure(
          cb, "InsertO1", pkey, a_int.get(i), a_inline_str.get(i), a_pool_str.get(i));

      if (!async) {
        cb.waitForResponse();
        VoltTable vt = cb.getResponse().getResults()[0];
        assertTrue(vt.getRowCount() == 1);
      }
      pkey = pkey + 1;
    }

    client.drain();
  }
Example #7
0
  public VoltTable[] run(long appId, long hashedDeviceId) throws IOException {

    // get the HLL from the db
    voltQueueSQL(estimatesSelect, EXPECT_ZERO_OR_ONE_ROW, appId);
    VoltTable estimatesTable = voltExecuteSQL()[0];

    HyperLogLog hll = null;
    // if the row with the hyperloglog blob exists...
    if (estimatesTable.advanceRow()) {
      byte[] hllBytes = estimatesTable.getVarbinary("hll");
      hll = HyperLogLog.fromBytes(hllBytes);
    }
    // otherwise create a hyperloglog blob
    else {
      hll = new HyperLogLog(12);
    }

    // offer the hashed device id to the HLL
    hll.offerHashed(hashedDeviceId);

    // if the estimates row needs updating, upsert it
    if (hll.getDirty()) {
      // update the state with exact estimate and update blob for the hll
      voltQueueSQL(
          estimatesUpsert, EXPECT_SCALAR_MATCH(1), appId, hll.cardinality(), hll.toBytes());
      return voltExecuteSQL(true);
    }
    return null;
  }
  public void validateRankFunction(String sql, int expectedCol) throws Exception {
    Client client = getClient();

    long input[][] = expected.clone();
    shuffleArrayOfLongs(input);
    ClientResponse cr;
    VoltTable vt;

    cr = client.callProcedure("@AdHoc", "TRUNCATE TABLE T");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    for (long[] row : input) {
      cr = client.callProcedure("T.insert", row[colA], row[colB], row[colC]);
      assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    }
    cr = client.callProcedure("@AdHoc", sql);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = cr.getResults()[0];
    for (int rowIdx = 0; vt.advanceRow(); rowIdx += 1) {
      String msg = String.format("Row %d:", rowIdx);
      assertEquals(msg, expected[rowIdx][colA], vt.getLong(0));
      assertEquals(msg, expected[rowIdx][colB], vt.getLong(1));
      assertEquals(msg, expected[rowIdx][colC], vt.getLong(2));
      assertEquals(msg, expected[rowIdx][expectedCol], vt.getLong(3));
    }
  }
  private VoltTable evictData(Table catalog_tbl) throws Exception {
    VoltTable results[] = this.ee.getStats(SysProcSelector.TABLE, this.locators, false, 0L);
    assertEquals(1, results.length);
    // System.err.println(VoltTableUtil.format(results));
    while (results[0].advanceRow()) {
      if (results[0].getString("TABLE_NAME").equalsIgnoreCase(catalog_tbl.getName()) == false)
        continue;
      for (String col : statsFields) {
        int idx = results[0].getColumnIndex(col);
        assertEquals(0, results[0].getLong(idx));
      } // FOR
    } // WHILE

    // Now force the EE to evict our boys out
    // We'll tell it to remove 1MB, which is guaranteed to include all of our tuples
    VoltTable evictResult = this.ee.antiCacheEvictBlock(catalog_tbl, 1024 * 1024, 1);

    //        System.err.println("-------------------------------");
    //        System.err.println(VoltTableUtil.format(evictResult));
    assertNotNull(evictResult);
    assertEquals(1, evictResult.getRowCount());
    assertNotSame(results[0].getColumnCount(), evictResult.getColumnCount());
    evictResult.resetRowPosition();
    boolean adv = evictResult.advanceRow();
    assertTrue(adv);
    return (evictResult);
  }
 protected void validateRowSeenAtAllPartitions(
     VoltTable result, String columnName, String targetValue, boolean enforceUnique) {
   result.resetRowPosition();
   Set<Integer> partsSeen = new HashSet<>();
   while (result.advanceRow()) {
     String colValFromRow = result.getString(columnName);
     if (targetValue.equalsIgnoreCase(colValFromRow)) {
       int thisPartId = (int) result.getLong("PARTITION_ID");
       if (enforceUnique) {
         assertFalse(
             "PARTITION_ID: "
                 + thisPartId
                 + " seen twice in table looking for "
                 + targetValue
                 + " in column "
                 + columnName,
             partsSeen.contains(thisPartId));
       }
       partsSeen.add(thisPartId);
     }
   }
   // Remove the MPI in case it's in there
   partsSeen.remove(MpInitiator.MP_INIT_PID);
   assertEquals(PARTITIONS, partsSeen.size());
 }
  public VoltTable[] run(
      short w_id,
      byte d_id,
      double h_amount,
      short c_w_id,
      byte c_d_id,
      byte[] 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) {
      String c_lastString = null;
      try {
        c_lastString = new String(c_last, "UTF-8");
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
      throw new VoltAbortException(
          "paymentByCustomerNameC: no customers with last name: "
              + c_lastString
              + " 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);
  }
  public void testStatistics_Procedure() throws Exception {
    Client client = getClient();
    VoltTable results[] = null;
    // 3 seconds translates to 3 billion nanos, which overflows internal
    // values (ENG-1039)
    results = client.callProcedure("GoSleep", 3000, 0, null).getResults();
    results = client.callProcedure("@Statistics", "procedure", 0).getResults();
    // one aggregate table returned
    assertTrue(results.length == 1);
    System.out.println("Test procedures table: " + results[0].toString());

    VoltTable stats = results[0];
    stats.advanceRow();
    // Check for overflow
    long min_time = (Long) stats.get("MIN_EXECUTION_TIME", VoltType.BIGINT);
    long max_time = (Long) stats.get("MAX_EXECUTION_TIME", VoltType.BIGINT);
    long avg_time = (Long) stats.get("AVG_EXECUTION_TIME", VoltType.BIGINT);
    assertTrue("Failed MIN_EXECUTION_TIME > 0, value was: " + min_time, min_time > 0);
    assertTrue("Failed MAX_EXECUTION_TIME > 0, value was: " + max_time, max_time > 0);
    assertTrue("Failed AVG_EXECUTION_TIME > 0, value was: " + avg_time, avg_time > 0);

    // check for reasonable values
    assertTrue(
        "Failed MIN_EXECUTION_TIME > 2,400,000,000ns, value was: " + min_time,
        min_time > 2400000000L);
    assertTrue(
        "Failed MAX_EXECUTION_TIME > 2,400,000,000ns, value was: " + max_time,
        max_time > 2400000000L);
    assertTrue(
        "Failed AVG_EXECUTION_TIME > 2,400,000,000ns, value was: " + avg_time,
        avg_time > 2400000000L);
  }
 protected boolean validateRowSeenAtAllSites(
     VoltTable result, String columnName, String targetValue, boolean enforceUnique) {
   result.resetRowPosition();
   Set<Long> sitesSeen = new HashSet<Long>();
   while (result.advanceRow()) {
     String colValFromRow = result.getString(columnName);
     if (targetValue.equalsIgnoreCase(colValFromRow)) {
       long hostId = result.getLong("HOST_ID");
       long thisSiteId = result.getLong("SITE_ID");
       thisSiteId |= hostId << 32;
       if (enforceUnique) {
         assertFalse(
             "SITE_ID: "
                 + thisSiteId
                 + " seen twice in table looking for "
                 + targetValue
                 + " in column "
                 + columnName,
             sitesSeen.contains(thisSiteId));
       }
       sitesSeen.add(thisSiteId);
     }
   }
   return (HOSTS * SITES) == sitesSeen.size();
 }
  public void testMultimapKeyOwnership() throws Exception {
    final Client client = this.getClient();
    ClientResponse response;
    VoltTable table;

    response = client.callProcedure("InsertT1", "a1", "b", "c1");
    assertEquals(1, getLongFromResponse(response));

    response = client.callProcedure("InsertT1", "a2", "b", "c2");
    assertEquals(1, getLongFromResponse(response));

    response = client.callProcedure("DeleteT1", "c1");
    assertEquals(1, getLongFromResponse(response));

    response = client.callProcedure("LookupT1b", "b");
    table = getSingleRowTable(response);
    System.out.println(table.toJSONString());

    // Try to repro a string memory management related crash when a no-op update corrupts an index.
    response = client.callProcedure("UpdateT1b", "b", "a2");
    assertEquals(1, getLongFromResponse(response));

    // This will cause a server fatal error if the corruption happened.
    response = client.callProcedure("UpdateT1b", "b2", "a2");
    assertEquals(1, getLongFromResponse(response));
  }
Example #15
0
  public VoltTable run(
      int behavior, // 0 don't set anything 1, set both, 2, set app status code, 3 set status code
      // and string, 4 set them both and abort
      String statusString,
      byte statusCode) {
    VoltTable result = new VoltTable(new VoltTable.ColumnInfo("a", VoltType.BIGINT));
    switch (behavior) {
      case 0:
        break;
      case 1:
        result.setStatusCode(statusCode);
        setAppStatusCode(statusCode);
        setAppStatusString(statusString);
        break;
      case 2:
        result.setStatusCode(statusCode);
        setAppStatusCode(statusCode);
        break;
      case 3:
        result.setStatusCode(statusCode);
        setAppStatusString(statusString);
        break;
      case 4:
        result.setStatusCode(statusCode);
        setAppStatusCode(statusCode);
        setAppStatusString(statusString);
        throw new VoltAbortException();
      default:
        throw new VoltAbortException("Invalid behavior value " + behavior);
    }

    return result;
  }
  public VoltTable[] run(long f_id) {
    final boolean debug = LOG.isDebugEnabled();

    // Empty seats bitmap
    final long seatmap[] = new long[SEATSConstants.FLIGHTS_NUM_SEATS];
    Arrays.fill(seatmap, -1);

    voltQueueSQL(GetFlight, f_id);
    voltQueueSQL(GetSeats, f_id);
    final VoltTable[] results = voltExecuteSQL(true);
    assert (results.length == 2);

    // First calculate the seat price using the flight's base price
    // and the number of seats that remaining
    if (results[0].advanceRow() == false) {
      throw new VoltAbortException(
          ErrorType.INVALID_FLIGHT_ID + String.format(" Invalid flight #%d", f_id));
    }

    int col = 6;
    double base_price = results[0].getDouble(col++); // F_BASE_PRICE
    long seats_total = results[0].getLong(col++); // F_SEATS_TOTAL
    long seats_left = results[0].getLong(col++); // F_SEATS_LEFT
    double seat_price = results[0].getDouble(col++); // MATHS!

    if (debug) {
      // TODO: Figure out why this doesn't match the SQL
      double _seat_price = base_price + (base_price * (1.0 - (seats_left / (double) seats_total)));
      LOG.debug(
          String.format(
              "Flight %d - SQL[%.2f] <-> JAVA[%.2f] [basePrice=%f, total=%d, left=%d]",
              f_id, seat_price, _seat_price, base_price, seats_total, seats_left));
    }

    // Then build the seat map of the remaining seats
    while (results[1].advanceRow()) {
      long r_id = results[1].getLong(0);
      int seatnum = (int) results[1].getLong(2);
      if (debug) LOG.debug(String.format("ROW fid %d rid %d seat %d", f_id, r_id, seatnum));
      assert (seatmap[seatnum] == -1) : "Duplicate seat reservation: R_ID=" + r_id;
      seatmap[seatnum] = 1; // results[1].getLong(1);
    } // WHILE

    int ctr = 0;
    VoltTable returnResults = new VoltTable(outputColumns);
    for (int i = 0; i < seatmap.length; ++i) {
      if (seatmap[i] == -1) {
        Object[] row = new Object[] {f_id, i, seat_price};
        returnResults.addRow(row);
        if (ctr == SEATSConstants.FLIGHTS_NUM_SEATS) break;
      }
    } // FOR
    //        assert(seats_left == returnResults.getRowCount()) :
    //            String.format("Flight %d - Expected[%d] != Actual[%d]", f_id, seats_left,
    // returnResults.getRowCount());

    if (debug) LOG.debug(String.format("Flight %d Open Seats:\n%s", f_id, returnResults));
    return new VoltTable[] {results[0], returnResults};
  }
 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());
   }
 }
  public void testENG1808() throws IOException, ProcCallException {
    Client client = this.getClient();

    client.callProcedure("A.insert", 1, 1);

    VoltTable result = client.callProcedure("@AdHoc", "select I from A limit 0").getResults()[0];

    assertEquals(0, result.getRowCount());
  }
Example #19
0
  public void test_Interface(
      String[] my_options, String[] my_data, int invalidLineCnt, int validLineCnt)
      throws Exception {
    try {
      BufferedWriter out_csv = new BufferedWriter(new FileWriter(path_csv));
      for (String aMy_data : my_data) {
        out_csv.write(aMy_data + "\n");
      }
      out_csv.flush();
      out_csv.close();
    } catch (Exception e) {
      System.err.print(e.getMessage());
    }

    CSVLoader.testMode = true;
    CSVLoader.main(my_options);
    // do the test

    VoltTable modCount;
    modCount = client.callProcedure("@AdHoc", "SELECT * FROM BLAH;").getResults()[0];
    System.out.println("data inserted to table BLAH:\n" + modCount);
    int rowct = modCount.getRowCount();

    // Call validate partitioning to check if we are good.
    VoltTable valTable;
    valTable = client.callProcedure("@ValidatePartitioning", null, null).getResults()[0];
    System.out.println("Validate for BLAH:\n" + valTable);
    while (valTable.advanceRow()) {
      long miscnt = valTable.getLong("MISPARTITIONED_ROWS");
      assertEquals(miscnt, 0);
    }

    BufferedReader csvreport = new BufferedReader(new FileReader(CSVLoader.pathReportfile));
    int lineCount = 0;
    String line;
    String promptMsg = "Number of rows successfully inserted:";
    String promptFailMsg = "Number of rows that could not be inserted:";
    int invalidlinecnt = 0;

    while ((line = csvreport.readLine()) != null) {
      if (line.startsWith(promptMsg)) {
        String num = line.substring(promptMsg.length());
        lineCount = Integer.parseInt(num.replaceAll("\\s", ""));
      }
      if (line.startsWith(promptFailMsg)) {
        String num = line.substring(promptFailMsg.length());
        invalidlinecnt = Integer.parseInt(num.replaceAll("\\s", ""));
      }
    }
    csvreport.close();
    System.out.println(String.format("The rows infected: (%d,%s)", lineCount, rowct));
    assertEquals(lineCount, rowct);
    // assert validLineCnt specified equals the successfully inserted lineCount
    assertEquals(validLineCnt, lineCount);
    assertEquals(invalidLineCnt, invalidlinecnt);
  }
Example #20
0
 private final void loadCodeXref(VoltTable vt, String codeCol, String idCol) {
   Map<String, Long> m = this.code_id_xref.get(idCol);
   while (vt.advanceRow()) {
     long id = vt.getLong(0);
     String code = vt.getString(1);
     m.put(code, id);
   } // WHILE
   if (debug.val)
     LOG.debug(String.format("Loaded %d xrefs for %s -> %s", m.size(), codeCol, idCol));
 }
Example #21
0
 void callWithExpectedCount(Client client, int count, String procName, Object... params)
     throws NoConnectionsException, IOException, ProcCallException {
   ClientResponse cr = client.callProcedure(procName, params);
   assertEquals(ClientResponse.SUCCESS, cr.getStatus());
   assertEquals(1, cr.getResults().length);
   VoltTable result = cr.getResults()[0];
   assertEquals(1, result.getRowCount());
   assertTrue(result.advanceRow());
   assertEquals(count, result.getLong(0));
 }
Example #22
0
  public VoltTable[] getOrderStatus(short w_id, byte d_id, int c_id, VoltTable customer) {
    voltQueueSQL(getLastOrder, w_id, d_id, c_id);
    final VoltTable order = voltExecuteSQL()[0];

    final long o_id = order.fetchRow(0).getLong(O_ID_IDX);
    voltQueueSQL(getOrderLines, w_id, o_id, d_id);
    final VoltTable orderLines = voltExecuteSQL()[0];

    return new VoltTable[] {customer, order, orderLines};
  }
Example #23
0
 /** 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();
 }
Example #24
0
  public VoltTable[] run(long phoneNumber, int contestantNumber, long maxVotesPerPhoneNumber) {
    VoltTable result =
        new VoltTable(
            new ColumnInfo("STATUS", VoltType.BIGINT), new ColumnInfo("REJECTED", VoltType.BIGINT));

    // Queue up validation statements
    voltQueueSQL(checkContestantStmt, EXPECT_ZERO_OR_ONE_ROW, contestantNumber);
    voltQueueSQL(checkVoterStmt, EXPECT_ZERO_OR_ONE_ROW, phoneNumber);
    voltQueueSQL(checkStateStmt, EXPECT_ZERO_OR_ONE_ROW, (short) (phoneNumber / 10000000l));
    voltQueueSQL(checkRejectedVotesStmt, EXPECT_ZERO_OR_ONE_ROW, phoneNumber);
    VoltTable validation[] = voltExecuteSQL();

    if (validation[0].getRowCount() == 0) {
      result.addRow(ERR_INVALID_CONTESTANT, -1);
      return new VoltTable[] {result};
    }

    // Get rejected votes
    long rejectedVotes = 1;
    if (validation[3].getRowCount() == 1) {
      rejectedVotes = validation[3].asScalarLong() + 1;
    }

    if ((validation[1].getRowCount() == 1)
        && (validation[1].asScalarLong() >= maxVotesPerPhoneNumber)) {
      if (validation[3].getRowCount() == 1) {
        // Increment count
        voltQueueSQL(incrementRejectedVotesStmt, phoneNumber);
      } else {
        // insert
        voltQueueSQL(insertRejectedVotesStmt, phoneNumber, 1);
      }
      voltExecuteSQL();

      result.addRow(ERR_VOTER_OVER_VOTE_LIMIT, rejectedVotes);
      return new VoltTable[] {result};
    }

    // Some sample client libraries use the legacy random phone generation that mostly
    // created invalid phone numbers. Until refactoring, re-assign all such votes to
    // the "XX" fake state (those votes will not appear on the Live Statistics dashboard,
    // but are tracked as legitimate instead of invalid, as old clients would mostly get
    // it wrong and see all their transactions rejected).
    final String state =
        (validation[2].getRowCount() > 0) ? validation[2].fetchRow(0).getString(0) : "XX";

    // Post the vote
    voltQueueSQL(insertVoteStmt, EXPECT_SCALAR_MATCH(1), phoneNumber, state, contestantNumber);
    voltExecuteSQL(true);

    // Set the return value to 0: successful vote
    result.addRow(VOTE_SUCCESSFUL, rejectedVotes);
    return new VoltTable[] {result};
  }
Example #25
0
  protected static void checkQueryPlan(Client client, String query, String... patterns)
      throws Exception {
    VoltTable vt;
    assert (patterns.length >= 1);

    vt = client.callProcedure("@Explain", query).getResults()[0];
    String vtStr = vt.toString();

    for (String pattern : patterns) {
      assertTrue(vtStr.contains(pattern));
    }
  }
 private void validateSubqueryWithWindowedAggregate(Client client, String sql)
     throws IOException, NoConnectionsException, ProcCallException {
   ClientResponse cr;
   VoltTable vt;
   cr = client.callProcedure("@AdHoc", sql);
   assertEquals(ClientResponse.SUCCESS, cr.getStatus());
   vt = cr.getResults()[0];
   int nc = vt.getColumnCount();
   while (vt.advanceRow()) {
     assertEquals(vt.getLong(nc - 2), vt.getLong(nc - 1));
   }
 }
Example #27
0
 /** sums the contents of a latency bucket table. */
 private long[] latencySummaryHelper(VoltTable vt) {
   long sums[] = new long[20];
   for (int i = 0; i < vt.getRowCount(); i++) {
     VoltTableRow row = vt.fetchRow(i);
     // 20  buckets
     for (int c = 0; c < 20; c++) {
       // 7 ignored header columns
       sums[c] += row.getLong(c + 7);
     }
   }
   return sums;
 }
Example #28
0
 /** 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;
 }
Example #29
0
 private void initializePartitionKeys()
     throws NoConnectionsException, IOException, ProcCallException {
   VoltTable keyTables = m_client.callProcedure("@GetPartitionKeys", "STRING").getResults()[0];
   m_partitionkeys = new String[keyTables.getRowCount()];
   while (keyTables.advanceRow()) {
     String partkey = keyTables.getString(1);
     int partition =
         (int)
             ((ClientImpl) m_client).getPartitionForParameter(VoltType.STRING.getValue(), partkey);
     m_partitionkeys[partition] = partkey;
   }
 }
Example #30
0
  /**
   * Perform a schema change to a mutated version of the current table (80%) or to a new table
   * entirely (20%, drops and adds the new table).
   */
  static VoltTable catalogChange(VoltTable t1, boolean newTable) throws Exception {
    CatalogBuilder builder = new CatalogBuilder();
    VoltTable t2 = null;
    String currentName = t1 == null ? "B" : TableHelper.getTableName(t1);
    String newName = currentName;

    if (newTable) {
      newName = currentName.equals("A") ? "B" : "A";
      t2 = TableHelper.getTotallyRandomTable(newName, rand);
    } else {
      t2 = TableHelper.mutateTable(t1, false, rand);
    }

    System.out.printf("New Schema:\n%s\n", TableHelper.ddlForTable(t2));

    builder.addLiteralSchema(TableHelper.ddlForTable(t2));
    // make tables name A partitioned and tables named B replicated
    if (newName.equalsIgnoreCase("A")) {
      int pkeyIndex = TableHelper.getBigintPrimaryKeyIndexIfExists(t2);
      builder.addPartitionInfo(newName, t2.getColumnName(pkeyIndex));
    }
    byte[] catalogData = builder.compileToBytes();
    assert (catalogData != null);

    long count = tupleCount(t1);
    long start = System.nanoTime();

    if (newTable) {
      System.out.println("Starting catalog update to swap tables.");
    } else {
      System.out.println("Starting catalog update to change schema.");
    }

    ClientResponse cr = client.callProcedure("@UpdateApplicationCatalog", catalogData, null);
    assert (cr.getStatus() == ClientResponse.SUCCESS);

    long end = System.nanoTime();
    double seconds = (end - start) / 1000000000.0;

    if (newTable) {
      System.out.printf("Completed catalog update that swapped tables in %.4f seconds\n", seconds);
    } else {
      System.out.printf(
          "Completed catalog update of %d tuples in %.4f seconds (%d tuples/sec)\n",
          count, seconds, (long) (count / seconds));
    }

    System.out.println("Sleeping for 5s");
    Thread.sleep(5000);

    return t2;
  }