public void testRankWithTimestamp() throws Exception {
    Client client = getClient();

    long baseTime = TimestampType.millisFromJDBCformat("1953-06-10 00:00:00");
    long input[][] = expected.clone();
    shuffleArrayOfLongs(input);
    ClientResponse cr;
    VoltTable vt;
    for (long[] row : input) {
      cr =
          client.callProcedure(
              "T_TIMESTAMP.insert",
              row[colA],
              row[colB],
              new TimestampType(baseTime + row[colB] * 1000));
      assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    }
    String sql =
        "select A, B, C, rank() over (partition by A order by C) as R from T_TIMESTAMP ORDER BY A, B, C, R;";
    cr = client.callProcedure("@AdHoc", sql);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = cr.getResults()[0];
    assertEquals(expected.length, vt.getRowCount());
    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, baseTime + expected[rowIdx][colB] * 1000, vt.getTimestampAsLong(2));
      assertEquals(msg, expected[rowIdx][colR_A], vt.getLong(3));
    }
  }
  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));
    }
  }
Example #3
0
  public void testThreeColumnsUniqueIndex() throws Exception {
    Client client = getClient();
    client.callProcedure("TU4.insert", 1, 1, "xin", 0);
    client.callProcedure("TU4.insert", 2, 2, "xin", 1);
    client.callProcedure("TU4.insert", 3, 3, "xin", 0);
    client.callProcedure("TU4.insert", 4, 6, "xin", 1);
    client.callProcedure("TU4.insert", 5, 8, "xin", 0);
    client.callProcedure("TU4.insert", 6, 1, "jia", 0);
    client.callProcedure("TU4.insert", 7, 2, "jia", 1);
    client.callProcedure("TU4.insert", 8, 3, "jia", 0);
    client.callProcedure("TU4.insert", 9, 6, "jia", 1);
    client.callProcedure("TU4.insert", 10, 8, "jia", 0);

    VoltTable table;
    // test with 2,6
    table =
        client.callProcedure(
                "@AdHoc", "SELECT COUNT(*) FROM TU4 WHERE UNAME = 'xin' AND SEX = 0 AND POINTS < 6")
            .getResults()[0];
    assertTrue(table.getRowCount() == 1);
    assertTrue(table.advanceRow());
    assertEquals(2, table.getLong(0));

    table =
        client.callProcedure(
                "@AdHoc",
                "SELECT COUNT(*) FROM TU4 WHERE UNAME = 'xin' AND SEX = 0 AND POINTS >= 2 AND POINTS < 6")
            .getResults()[0];
    assertTrue(table.getRowCount() == 1);
    assertTrue(table.advanceRow());
    assertEquals(1, table.getLong(0));
  }
  /**
   * Check the result of a query that has only an OFFSET and no LIMIT clause. This is done by
   * executing the query with and without the offset clause, and then skipping past the offset rows
   * in the expected table here on the client side.
   */
  private static void doOffsetAndCheck(Client client, String stmt)
      throws IOException, InterruptedException, ProcCallException {
    String stmtNoOffset = stmt.substring(0, stmt.indexOf("OFFSET"));
    VoltTable expectedTable = client.callProcedure("@AdHoc", stmtNoOffset).getResults()[0];
    int rowCountBeforeOffset = expectedTable.getRowCount();

    int[] offsets = {0, 1, 5, 10, 11, 15};
    for (int offset : offsets) {
      VoltTable actualTable = client.callProcedure("@AdHoc", stmt, offset).getResults()[0];
      int expectedRowCount = Math.max(rowCountBeforeOffset - offset, 0);
      assertEquals(
          "Actual table has wrong number of rows: ", expectedRowCount, actualTable.getRowCount());
      if (actualTable.getRowCount() == 0) continue;

      // non-empty result.
      // Advance expected table past offset
      // then compare what's left.
      actualTable.resetRowPosition();
      for (int i = 0; i < offset; ++i) expectedTable.advanceRow();

      while (actualTable.advanceRow() && expectedTable.advanceRow()) {
        assertEquals(expectedTable.getLong(0), actualTable.getLong(0));
        assertEquals(expectedTable.getLong(1), actualTable.getLong(1));
      }
    }
  }
 public VoltTable[] doWork(SQLStmt select, SQLStmt insert, long cid) {
   if (select != null) { // use select / insert
     // Get row for cid and copy to new table.
     voltQueueSQL(select, cid);
     VoltTable[] results = voltExecuteSQL();
     VoltTable data = results[0];
     if (data.getRowCount() != 1) {
       throw new VoltAbortException("Failed to find cid that should exist: cid=" + cid);
     }
     data.advanceRow();
     long rcid = data.getLong(0);
     if (rcid != cid) {
       throw new VoltAbortException(
           "Failed to find cid does not match. (" + rcid + ":" + cid + ")");
     }
     long txnid = data.getLong(1);
     long rowid = data.getLong(2);
     voltQueueSQL(insert, rcid, txnid, rowid);
     return voltExecuteSQL();
   } else { // use insert into
     voltQueueSQL(insert, cid);
     VoltTable[] results = voltExecuteSQL();
     VoltTable data = results[0];
     int cnt = (int) data.fetchRow(0).getLong(0);
     if (cnt != 1) {
       throw new VoltAbortException(
           "incorrect number of inserted rows=" + cnt + " for cid=" + cid);
     }
     return results;
   }
 }
 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();
 }
 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));
   }
 }
 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());
 }
  /** 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 #10
0
  private int countHostsProvidingRows(
      VoltTable result, Map<String, String> columnTargets, boolean enforceUnique) {
    result.resetRowPosition();
    Set<Long> hostsSeen = new HashSet<Long>();
    while (result.advanceRow()) {
      if (checkRowForMultipleTargets(result, columnTargets)) {
        Long thisHostId = result.getLong("HOST_ID");
        if (enforceUnique) {
          StringBuilder message = new StringBuilder();
          message.append("HOST_ID: " + thisHostId + " seen twice in table looking for ");
          for (Entry<String, String> entry : columnTargets.entrySet()) {
            message.append(entry.getValue() + " in column " + entry.getKey() + ";");
          }
          assertFalse(message.toString(), hostsSeen.contains(thisHostId));
        }
        hostsSeen.add(thisHostId);
      }
    }

    // * Enable this to force a failure with diagnostics */ hostsSeen.add(123456789L);

    // Before possibly failing an assert, prepare to report details of the non-conforming result.
    m_recentAnalysis = null;
    if (HOSTS != hostsSeen.size()) {
      m_recentAnalysis = new StringBuilder();
      m_recentAnalysis.append("Failure follows from these results:\n");
      Set<Long> seenAgain = new HashSet<Long>();
      result.resetRowPosition();
      while (result.advanceRow()) {
        Long thisHostId = result.getLong("HOST_ID");
        String rowStatus = "Found a non-match";
        if (checkRowForMultipleTargets(result, columnTargets)) {
          if (seenAgain.add(thisHostId)) {
            rowStatus = "Added a match";
          } else {
            rowStatus = "Duplicated a match";
          }
        }
        m_recentAnalysis.append(rowStatus + " at host " + thisHostId + " for ");
        for (String key : columnTargets.keySet()) {
          m_recentAnalysis.append(key + " " + result.getString(key) + ";");
        }
        m_recentAnalysis.append("\n");
      }
    }
    return hostsSeen.size();
  }
  public void testRankWithString() throws Exception {
    Client client = getClient();

    long input[][] = expected.clone();
    shuffleArrayOfLongs(input);
    ClientResponse cr;
    VoltTable vt;
    for (long[] row : input) {
      cr =
          client.callProcedure(
              "T_STRING.insert", row[colA], row[colB], Long.toString(row[colC], 10));
      assertEquals(ClientResponse.SUCCESS, cr.getStatus());
      cr =
          client.callProcedure(
              "T_STRING_A.insert", Long.toString(row[colA], 10), row[colB], row[colC]);
      assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    }
    String sql;
    // Test string values
    sql =
        "select A, B, C, rank() over (partition by A order by B) as R from T_STRING ORDER BY A, B, C, R;";
    cr = client.callProcedure("@AdHoc", sql);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = cr.getResults()[0];
    assertEquals(expected.length, vt.getRowCount());
    for (int rowIdx = 0; vt.advanceRow(); rowIdx += 1) {
      assertEquals(expected[rowIdx][colA], vt.getLong(0));
      assertEquals(expected[rowIdx][colB], vt.getLong(1));
      assertEquals(Long.toString(expected[rowIdx][colC], 10), vt.getString(2));
      assertEquals(expected[rowIdx][colR_A], vt.getLong(3));
    }
    // Test with partition by over a string column
    sql =
        "select A, B, C, rank() over (partition by A order by B) as R from T_STRING_A ORDER BY A, B, C, R;";
    cr = client.callProcedure("@AdHoc", sql);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = cr.getResults()[0];
    assertEquals(expected.length, vt.getRowCount());
    for (int rowIdx = 0; vt.advanceRow(); rowIdx += 1) {
      assertEquals(Long.toString(expected[rowIdx][colA], 10), vt.getString(0));
      assertEquals(expected[rowIdx][colB], vt.getLong(1));
      assertEquals(expected[rowIdx][colC], vt.getLong(2));
      assertEquals(expected[rowIdx][colR_A], vt.getLong(3));
    }
  }
Example #12
0
  protected static void validStatisticsForTableLimitAndPercentage(
      Client client, String tableName, long limit, long percentage) throws Exception {
    long start = System.currentTimeMillis();
    while (true) {
      long lastLimit = -1, lastPercentage = -1;
      Thread.sleep(1000);
      if (System.currentTimeMillis() - start > 10000) {
        String percentageStr = "";
        if (percentage >= 0) {
          percentageStr = ", last seen percentage: " + lastPercentage;
        }
        fail("Took too long or have wrong answers: last seen limit: " + lastLimit + percentageStr);
      }

      VoltTable[] results = client.callProcedure("@Statistics", "TABLE", 0).getResults();
      for (VoltTable t : results) {
        System.out.println(t.toString());
      }
      if (results[0].getRowCount() == 0) continue;

      boolean foundTargetTuple = false;
      boolean limitExpected = false;
      boolean percentageExpected = percentage < 0 ? true : false;

      for (VoltTable vt : results) {
        while (vt.advanceRow()) {
          String name = vt.getString("TABLE_NAME");
          if (tableName.equals(name)) {
            foundTargetTuple = true;
            lastLimit = vt.getLong("TUPLE_LIMIT");
            if (limit == lastLimit) {
              limitExpected = true;
            }
            if (percentageExpected || percentage == (lastPercentage = vt.getLong("PERCENT_FULL"))) {
              percentageExpected = true;
            }

            if (limitExpected && percentageExpected) return;
            break;
          }
        }
        if (foundTargetTuple) break;
      }
    }
  }
Example #13
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 #14
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 #15
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 #16
0
 private final void loadConfigProfile(VoltTable vt) {
   boolean adv = vt.advanceRow();
   assert (adv)
       : "No data in "
           + SEATSConstants.TABLENAME_CONFIG_PROFILE
           + ". "
           + "Did you forget to load the database first?";
   int col = 0;
   this.scale_factor = vt.getDouble(col++);
   JSONUtil.fromJSONString(this.airport_max_customer_id, vt.getString(col++));
   this.flight_start_date = vt.getTimestampAsTimestamp(col++);
   this.flight_upcoming_date = vt.getTimestampAsTimestamp(col++);
   this.flight_past_days = vt.getLong(col++);
   this.flight_future_days = vt.getLong(col++);
   this.num_flights = vt.getLong(col++);
   this.num_customers = vt.getLong(col++);
   this.num_reservations = vt.getLong(col++);
   if (debug.val)
     LOG.debug(String.format("Loaded %s data", SEATSConstants.TABLENAME_CONFIG_PROFILE));
 }
  public VoltTable[] run() {
    voltQueueSQL(resultStmt);
    VoltTable[] results1 = voltExecuteSQL(true);
    VoltTable t = results1[0];

    VoltTable t2 =
        new VoltTable(
            new VoltTable.ColumnInfo("rank", VoltType.INTEGER),
            new VoltTable.ColumnInfo("contestant_name", VoltType.STRING),
            new VoltTable.ColumnInfo("contestant_number", VoltType.INTEGER),
            new VoltTable.ColumnInfo("num_votes_expr", VoltType.BIGINT));

    int rank = 0;
    while (t.advanceRow()) {
      t2.addRow(
          new Object[] {rank++, t.getString(0), (int) t.getLong(1), (long) (t.getLong(2) + 10)});
    }

    return new VoltTable[] {t2};
  }
 public VoltTable run(int contestantNumber, int max) {
   ArrayList<Result> results = new ArrayList<Result>();
   voltQueueSQL(resultStmt);
   VoltTable summary = voltExecuteSQL()[0];
   String state = "";
   while (summary.advanceRow()) {
     if (!summary.getString(1).equals(state)) {
       state = summary.getString(1);
       if (summary.getLong(0) == contestantNumber)
         results.add(new Result(state, summary.getLong(2)));
     }
   }
   Result[] resultArray = (Result[]) results.toArray();
   Arrays.sort(resultArray, new OrderByVotesDesc());
   VoltTable result =
       new VoltTable(
           new VoltTable.ColumnInfo("state", VoltType.STRING),
           new VoltTable.ColumnInfo("num_votes", VoltType.BIGINT));
   for (int i = 0; i < Math.min(resultArray.length, max); i++)
     result.addRow(new Object[] {resultArray[i].state, resultArray[i].votes});
   return result;
 }
Example #19
0
 long getMBRss() {
   assert (m_client != null);
   try {
     ClientResponse r = m_client.callProcedure("@Statistics", "MEMORY", 0);
     VoltTable stats = r.getResults()[0];
     stats.advanceRow();
     long rss = stats.getLong("RSS") / 1024;
     return rss;
   } catch (Exception e) {
     e.printStackTrace();
     System.exit(-1);
     return 0;
   }
 }
Example #20
0
 /**
  * Print planner and cache statistics.
  *
  * @throws IOException
  * @throws NoConnectionsException
  */
 public void printPlannerStatistics() throws IOException, NoConnectionsException {
   try {
     VoltTable result = client.callProcedure("@Statistics", "PLANNER", 0).getResults()[0];
     while (result.advanceRow()) {
       String hostname = result.getString("HOSTNAME");
       long siteId = result.getLong("SITE_ID");
       long partitionId = result.getLong("PARTITION_ID");
       long hits1 = result.getLong("CACHE1_HITS");
       long hits2 = result.getLong("CACHE2_HITS");
       long level1 = result.getLong("CACHE1_LEVEL");
       long level2 = result.getLong("CACHE2_LEVEL");
       long misses = result.getLong("CACHE_MISSES");
       long total = hits1 + hits2 + misses;
       double hitpc1 = (100.0 * hits1) / total;
       double hitpc2 = (100.0 * hits2) / total;
       double planTimeMin = result.getLong("PLAN_TIME_MIN") / 1000000.0;
       double planTimeMax = result.getLong("PLAN_TIME_MAX") / 1000000.0;
       double planTimeAvg = result.getLong("PLAN_TIME_AVG") / 1000000.0;
       long failures = result.getLong("FAILURES");
       // Global stats
       System.out.printf("          HOSTNAME: %s\n", hostname);
       if (siteId == -1) {
         System.out.printf("              SITE: (global)\n");
       } else {
         System.out.printf("              SITE: %d\n", siteId);
         System.out.printf("         PARTITION: %d\n", partitionId);
       }
       System.out.printf("       TOTAL PLANS: %d\n", total);
       System.out.printf("      CACHE MISSES: %d\n", misses);
       if (siteId == -1) {
         System.out.printf("LEVEL 1 CACHE HITS: %d (%.1f%%)\n", hits1, hitpc1);
         System.out.printf("LEVEL 2 CACHE HITS: %d (%.1f%%)\n", hits2, hitpc2);
         System.out.printf("LEVEL 1 CACHE SIZE: %d\n", level1);
         System.out.printf("LEVEL 2 CACHE SIZE: %d\n", level2);
       } else {
         System.out.printf("   PLAN CACHE HITS: %d (%.1f%%)\n", hits1, hitpc1);
         System.out.printf("   PLAN CACHE SIZE: %d\n", level1);
       }
       System.out.printf("     PLAN TIME MIN: %6.2f ms\n", planTimeMin);
       System.out.printf("     PLAN TIME MAX: %6.2f ms\n", planTimeMax);
       System.out.printf("     PLAN TIME AVG: %6.2f ms\n", planTimeAvg);
       System.out.printf("          FAILURES: %d\n\n", failures);
     }
   } catch (ProcCallException e) {
     e.printStackTrace();
   }
 }
  private static void doLimitOffsetAndCheck(Client client, String proc)
      throws IOException, InterruptedException, ProcCallException {
    ClientResponse resp = client.callProcedure(proc, 4, 0);
    assertEquals(ClientResponse.SUCCESS, resp.getStatus());
    VoltTable[] results = resp.getResults();
    assertEquals(1, results.length);
    VoltTable vt = results[0];
    int i = 0;
    while (vt.advanceRow()) {
      assertEquals(i++, vt.getLong(1));
    }
    assertEquals(4, i);

    resp = client.callProcedure(proc, 3, 1);
    assertEquals(ClientResponse.SUCCESS, resp.getStatus());
    results = resp.getResults();
    assertEquals(1, results.length);
    vt = results[0];
    i = 1;
    while (vt.advanceRow()) {
      assertEquals(i++, vt.getLong(1));
    }
    assertEquals(4, i);
  }
  public void testRankOrderbyExpressions() throws Exception {
    Client client = getClient();

    long input[][] = expected.clone();
    shuffleArrayOfLongs(input);
    ClientResponse cr;
    VoltTable vt;
    for (long[] row : input) {
      cr = client.callProcedure("T.insert", row[colA], row[colB], row[colC]);
      assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    }
    String sql =
        "select A, B, C, rank() over (partition by A*A*A, A*A order by B*B) as R from T ORDER BY A, B, C, R;";
    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][colR_A], vt.getLong(3));
    }
  }
  public void testENG6485() throws IOException, ProcCallException {
    Client client = this.getClient();
    VoltTable result = null;

    String insertProc = "C.insert";
    client.callProcedure(insertProc, 1, 1, "foo");
    client.callProcedure(insertProc, 2, 1, "foo");
    client.callProcedure(insertProc, 3, 1, "foo");
    client.callProcedure(insertProc, 4, 1, "bar");
    client.callProcedure(insertProc, 5, 1, "bar");
    client.callProcedure(insertProc, 7, 1, "woof");
    client.callProcedure(insertProc, 8, 1, "woof");
    client.callProcedure(insertProc, 9, 1, "foo");
    client.callProcedure(insertProc, 10, 1, "foo");
    client.callProcedure(insertProc, 11, 2, "foo");
    client.callProcedure(insertProc, 12, 2, "foo");
    client.callProcedure(insertProc, 13, 2, "woof");
    client.callProcedure(insertProc, 14, 2, "woof");
    client.callProcedure(insertProc, 15, 2, "woof");
    client.callProcedure(insertProc, 16, 2, "bar");
    client.callProcedure(insertProc, 17, 2, "bar");
    client.callProcedure(insertProc, 18, 2, "foo");
    client.callProcedure(insertProc, 19, 2, "foo");

    result = client.callProcedure("@AdHoc", "SELECT COUNT(*) FROM C;").getResults()[0];
    validateTableOfScalarLongs(result, new long[] {18});

    result =
        client.callProcedure("@AdHoc", "SELECT name, count(id) FROM C GROUP BY name limit 1")
            .getResults()[0];
    if (result.advanceRow()) {
      String name = result.getString(0);
      long count = result.getLong(1);
      switch (name) {
        case "foo":
          assertEquals(9, count);
          break;
        case "bar":
          assertEquals(4, count);
          break;
        case "woof":
          assertEquals(5, count);
          break;
      }
    } else {
      fail("cannot get data from table c");
    }
  }
Example #24
0
  protected static void validateTableColumnOfScalarLong(VoltTable vt, int col, long[] expected) {
    assertNotNull(expected);
    assertEquals(expected.length, vt.getRowCount());
    int len = expected.length;
    for (int i = 0; i < len; i++) {
      assertTrue(vt.advanceRow());
      long actual = vt.getLong(col);

      if (expected[i] == Long.MIN_VALUE) {
        assertTrue(vt.wasNull());
        assertEquals(null, actual);
      } else {
        assertEquals(expected[i], actual);
      }
    }
  }
Example #25
0
  public void testTopoStatistics() throws Exception {
    System.out.println("\n\nTESTING TOPO STATS\n\n\n");
    Client client = getFullyConnectedClient();

    ColumnInfo[] expectedSchema1 = new ColumnInfo[3];
    expectedSchema1[0] = new ColumnInfo("Partition", VoltType.INTEGER);
    expectedSchema1[1] = new ColumnInfo("Sites", VoltType.STRING);
    expectedSchema1[2] = new ColumnInfo("Leader", VoltType.STRING);
    VoltTable expectedTable1 = new VoltTable(expectedSchema1);

    ColumnInfo[] expectedSchema2 = new ColumnInfo[2];
    expectedSchema2[0] = new ColumnInfo("HASHTYPE", VoltType.STRING);
    expectedSchema2[1] = new ColumnInfo("HASHCONFIG", VoltType.VARBINARY);
    VoltTable expectedTable2 = new VoltTable(expectedSchema2);

    VoltTable[] results = null;

    //
    // TOPO
    //
    results = client.callProcedure("@Statistics", "TOPO", 0).getResults();
    // two aggregate tables returned
    assertEquals(2, results.length);
    System.out.println("Test TOPO table: " + results[0].toString());
    System.out.println("Test TOPO table: " + results[1].toString());
    validateSchema(results[0], expectedTable1);
    validateSchema(results[1], expectedTable2);
    VoltTable topo = results[0];
    // Should have partitions + 1 rows in the first table
    assertEquals(PARTITIONS + 1, results[0].getRowCount());
    // Make sure we can find the MPI, at least
    boolean found = false;
    while (topo.advanceRow()) {
      if ((int) topo.getLong("Partition") == MpInitiator.MP_INIT_PID) {
        found = true;
      }
    }
    assertTrue(found);
    // and only one row in the second table
    assertEquals(1, results[1].getRowCount());
  }
  public void testENG3487() throws IOException, ProcCallException {
    Client client = this.getClient();

    client.callProcedure("A.insert", 1, 1);
    client.callProcedure("A.insert", 2, 1);
    client.callProcedure("A.insert", 3, 1);
    client.callProcedure("A.insert", 4, 4);
    client.callProcedure("A.insert", 5, 4);
    client.callProcedure("A.insert", 6, 9);

    VoltTable result =
        client.callProcedure(
                "@AdHoc", "select I, count(*) as tag from A group by I order by tag, I limit 1")
            .getResults()[0];

    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    // System.err.println("Result:\n" + result);
    assertEquals(9, result.getLong(0));
    assertEquals(1, result.getLong(1));
  }
Example #27
0
  protected static void validateRowOfLongs(String messagePrefix, VoltTable vt, long[] expected) {
    int len = expected.length;
    assertTrue(vt.advanceRow());
    for (int i = 0; i < len; i++) {
      String message = messagePrefix + "at column " + i + ", ";

      long actual = -10000000;
      // ENG-4295: hsql bug: HSQLBackend sometimes returns wrong column type.
      try {
        actual = vt.getLong(i);
      } catch (IllegalArgumentException ex) {
        try {
          actual = (long) vt.getDouble(i);
        } catch (IllegalArgumentException newEx) {
          try {
            actual = vt.getTimestampAsLong(i);
          } catch (IllegalArgumentException exTm) {
            try {
              actual = vt.getDecimalAsBigDecimal(i).longValueExact();
            } catch (IllegalArgumentException newerEx) {
              newerEx.printStackTrace();
              fail(message);
            }
          } catch (ArithmeticException newestEx) {
            newestEx.printStackTrace();
            fail(message);
          }
        }
      }

      // Long.MIN_VALUE is like a NULL
      if (expected[i] != Long.MIN_VALUE) {
        assertEquals(message, expected[i], actual);
      } else {
        VoltType type = vt.getColumnType(i);
        assertEquals(
            message + "expected null: ", Long.parseLong(type.getNullValue().toString()), actual);
      }
    }
  }
Example #28
0
  private final void loadConfigHistograms(VoltTable vt) {
    while (vt.advanceRow()) {
      int col = 0;
      String name = vt.getString(col++);
      ObjectHistogram<String> h =
          JSONUtil.fromJSONString(new ObjectHistogram<String>(), vt.getString(col++));
      boolean is_airline = (vt.getLong(col++) == 1);

      if (is_airline) {
        this.airport_histograms.put(name, h);
        if (trace.val)
          LOG.trace(
              String.format("Loaded %d records for %s airport histogram", h.getValueCount(), name));
      } else {
        this.histograms.put(name, h);
        if (trace.val)
          LOG.trace(String.format("Loaded %d records for %s histogram", h.getValueCount(), name));
      }
    } // WHILE
    if (debug.val)
      LOG.debug(String.format("Loaded %s data", SEATSConstants.TABLENAME_CONFIG_HISTOGRAMS));
  }
Example #29
0
  /**
   * Wait for export processor to catch up and have nothing to be exported.
   *
   * @param client
   * @throws Exception
   */
  public static void waitForStreamedAllocatedMemoryZero(Client client) throws Exception {
    boolean passed = false;

    VoltTable stats = null;
    try {
      System.out.println(client.callProcedure("@Quiesce").getResults()[0]);
    } catch (Exception ex) {
    }
    while (true) {
      try {
        stats = client.callProcedure("@Statistics", "table", 0).getResults()[0];
      } catch (Exception ex) {
      }
      if (stats == null) {
        Thread.sleep(5000);
        continue;
      }
      boolean passedThisTime = true;
      while (stats.advanceRow()) {
        String ttype = stats.getString("TABLE_TYPE");
        if (ttype.equals("StreamedTable")) {
          if (0 != stats.getLong("TUPLE_ALLOCATED_MEMORY")) {
            passedThisTime = false;
            System.out.println("Partition Not Zero.");
            break;
          }
        }
      }
      if (passedThisTime) {
        passed = true;
        break;
      }
      Thread.sleep(5000);
    }
    System.out.println("Passed is: " + passed);
    System.out.println(stats);
  }
  public void testRankPartitionedTable() throws Exception {
    Client client = getClient();

    long input[][] = expected.clone();
    shuffleArrayOfLongs(input);
    ClientResponse cr;
    VoltTable vt;
    for (long[] row : input) {
      cr = client.callProcedure("T_PA.insert", row[colA], row[colB], row[colC]);
      assertEquals(ClientResponse.SUCCESS, cr.getStatus());
      cr = client.callProcedure("T_PB.insert", row[colA], row[colB], row[colC]);
      assertEquals(ClientResponse.SUCCESS, cr.getStatus());
      cr = client.callProcedure("T_PC.insert", row[colA], row[colB], row[colC]);
      assertEquals(ClientResponse.SUCCESS, cr.getStatus());
      cr = client.callProcedure("T_PAA.insert", row[colA], row[colAA], row[colB], row[colC]);
    }
    String sql;
    // Test rank with partition by over a partitioned column.
    sql =
        "select A, B, C, rank() over (partition by A order by B) as R from T_PA ORDER BY A, B, C, R;";
    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][colR_A], vt.getLong(3));
    }
    // Test rank with ordered window over a partitioned column, and
    // partition not over a partitioned column.
    sql =
        "select A, B, C, rank() over (partition by A order by B) as R from T_PB ORDER BY A, B, C, R;";
    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][colR_A], vt.getLong(3));
    }
    // Select rank with neither partition nor rank over partioned
    // columns, but with a partitioned table.
    sql =
        "select A, B, C, rank() over (partition by A order by B) as R from T_PC ORDER BY A, B, C, R;";
    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][colR_A], vt.getLong(3));
    }
    // Check rank with windowed partition on two columns, one partitioned and
    // one not partitioned, but ordered by a non-partitioned column.
    sql =
        "select A, B, C, rank() over (partition by A, AA order by B) as R from T_PAA ORDER BY A, B, C, R;";
    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][colR_AA], vt.getLong(3));
    }
    // Check the previous case, but with the partition by order reversed.
    sql =
        "select A, B, C, rank() over (partition by AA, A order by B) as R from T_PAA ORDER BY A, AA, B, C, R;";
    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][colR_AA], vt.getLong(3));
    }
  }