/**
   * 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 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));
  }
Beispiel #3
0
  /** Populate Subscriber table per benchmark spec. */
  void genSubscriber(Table catalog_tbl) {
    final VoltTable table = CatalogUtil.getVoltTable(catalog_tbl);
    Object row[] = new Object[table.getColumnCount()];
    long total = 0;
    for (long s_id = 0; s_id < this.subscriberSize; s_id++) {
      int col = 0;
      row[col++] = s_id;
      row[col++] = TM1Util.padWithZero(s_id);

      // BIT_##
      for (int j = 0; j < 10; j++) {
        row[col++] = TM1Util.number(0, 1);
      } // FOR
      // HEX_##
      for (int j = 0; j < 10; j++) {
        row[col++] = TM1Util.number(0, 15);
      }
      // BYTE2_##
      for (int j = 0; j < 10; j++) {
        row[col++] = TM1Util.number(0, 255);
      }
      // MSC_LOCATION + VLR_LOCATION
      for (int j = 0; j < 2; j++) {
        row[col++] = TM1Util.number(0, Integer.MAX_VALUE);
      }
      assert col == table.getColumnCount();
      table.addRow(row);
      total++;

      if (table.getRowCount() >= TM1Constants.BATCH_SIZE) {
        if (d)
          LOG.debug(
              String.format(
                  "%s: %6d / %d", TM1Constants.TABLENAME_SUBSCRIBER, total, this.subscriberSize));
        loadVoltTable(TM1Constants.TABLENAME_SUBSCRIBER, table);
        table.clearRowData();
        assert (table.getRowCount() == 0);
      }
    } // FOR
    if (table.getRowCount() > 0) {
      if (d)
        LOG.debug(
            String.format(
                "%s: %6d / %d", TM1Constants.TABLENAME_SUBSCRIBER, total, this.subscriberSize));
      loadVoltTable(TM1Constants.TABLENAME_SUBSCRIBER, table);
      table.clearRowData();
      assert (table.getRowCount() == 0);
    }
  }
 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;
   }
 }
  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);
  }
Beispiel #6
0
 /** Called from the ExecutionEngine to request serialized dependencies. */
 public byte[] nextDependencyAsBytes(final int dependencyId) {
   final VoltTable vt = m_dependencyTracker.nextDependency(dependencyId);
   if (vt != null) {
     ByteBuffer buffer = vt.getDirectDataReference();
     if (d)
       LOG.debug(
           String.format(
               "Passing Dependency %d to EE [rows=%d, cols=%d, bytes=%d/%d]\n%s",
               dependencyId,
               vt.getRowCount(),
               vt.getColumnCount(),
               vt.getUnderlyingBufferSize(),
               buffer.array().length,
               vt.toString()));
     assert (buffer.hasArray());
     return (buffer.array());
   }
   // Note that we will hit this after retrieving all the VoltTables for the given dependencyId
   // It does not mean that there were no VoltTables at all, it just means that
   // we have gotten all of them
   else if (d) {
     LOG.warn(
         String.format(
             "Failed to find Dependency %d for EE [dep=%s, count=%d, ids=%s]",
             dependencyId,
             m_dependencyTracker.m_depsById.get(dependencyId),
             m_dependencyTracker.m_depsById.size(),
             m_dependencyTracker.m_depsById.keySet()));
   }
   return null;
 }
  /**
   * 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();
  }
  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 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);
  }
Beispiel #10
0
 protected static void validateTableOfScalarLongs(VoltTable vt, long[] expected) {
   assertNotNull(expected);
   assertEquals("Different number of rows! ", expected.length, vt.getRowCount());
   int len = expected.length;
   for (int i = 0; i < len; i++) {
     validateRowOfLongs(vt, new long[] {expected[i]});
   }
 }
Beispiel #11
0
 protected void validateTableOfDecimal(VoltTable vt, BigDecimal[][] expected) {
   assertNotNull(expected);
   assertEquals(expected.length, vt.getRowCount());
   int len = expected.length;
   for (int i = 0; i < len; i++) {
     validateRowOfDecimal(vt, expected[i]);
   }
 }
Beispiel #12
0
 protected static void validateTableOfLongs(VoltTable vt, long[][] expected) {
   assertNotNull(expected);
   assertEquals("Wrong number of rows in table.  ", expected.length, vt.getRowCount());
   int len = expected.length;
   for (int i = 0; i < len; i++) {
     validateRowOfLongs("at row " + i + ", ", vt, expected[i]);
   }
 }
  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));
    }
  }
Beispiel #14
0
 private static void validateTableOfLongs(String messagePrefix, VoltTable vt, long[][] expected) {
   assertNotNull(expected);
   if (expected.length != vt.getRowCount()) {
     if (vt.getRowCount() < m_verboseDiagnosticRowCap) {
       System.out.println(
           "Diagnostic dump of unexpected result for " + messagePrefix + " : " + vt);
       System.out.println("VS. expected : ");
       dumpExpectedLongs(expected);
     }
     // * enable and set breakpoint to debug multiple row count mismatches and continue */ return;
   }
   assertEquals(
       messagePrefix + " returned wrong number of rows.  ", expected.length, vt.getRowCount());
   int len = expected.length;
   for (int i = 0; i < len; i++) {
     validateRowOfLongs(messagePrefix + " at row " + i + ", ", vt, expected[i]);
   }
 }
  public void testDistinctLimitOffset()
      throws NoConnectionsException, IOException, ProcCallException {
    Client client = getClient();
    client.callProcedure("InsertA", 0, 1);
    client.callProcedure("InsertA", 1, 1);
    client.callProcedure("InsertA", 2, 2);
    VoltTable result = null;

    result =
        client.callProcedure("@AdHoc", "SELECT DISTINCT I FROM A LIMIT 1 OFFSET 1;")
            .getResults()[0];
    assertEquals(1, result.getRowCount());

    result =
        client.callProcedure("@AdHoc", "SELECT DISTINCT I FROM A LIMIT 0 OFFSET 1;")
            .getResults()[0];
    assertEquals(0, result.getRowCount());
  }
  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());
  }
Beispiel #17
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);
  }
Beispiel #18
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));
 }
Beispiel #19
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;
 }
Beispiel #20
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;
   }
 }
Beispiel #21
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;
 }
Beispiel #22
0
  /** Populate Access_Info table per benchmark spec. */
  void genAccessInfo(Table catalog_tbl) {
    final VoltTable table = CatalogUtil.getVoltTable(catalog_tbl);
    int[] arr = {1, 2, 3, 4};

    int[] ai_types = TM1Util.subArr(arr, 1, 4);
    long total = 0;
    for (long s_id = 0; s_id < this.subscriberSize; s_id++) {
      for (int ai_type : ai_types) {
        Object row[] = new Object[table.getColumnCount()];
        row[0] = s_id;
        row[1] = ai_type;
        row[2] = TM1Util.number(0, 255);
        row[3] = TM1Util.number(0, 255);
        row[4] = TM1Util.astring(3, 3);
        row[5] = TM1Util.astring(5, 5);
        table.addRow(row);
        total++;
      } // FOR
      if (table.getRowCount() >= TM1Constants.BATCH_SIZE) {
        if (d)
          LOG.debug(
              String.format(
                  "%s: %6d / %d",
                  TM1Constants.TABLENAME_ACCESS_INFO, total, ai_types.length * subscriberSize));
        loadVoltTable(TM1Constants.TABLENAME_ACCESS_INFO, table);
        table.clearRowData();
      }
    } // WHILE
    if (table.getRowCount() > 0) {
      if (d)
        LOG.debug(
            String.format(
                "%s: %6d / %d",
                TM1Constants.TABLENAME_ACCESS_INFO, total, ai_types.length * subscriberSize));
      loadVoltTable(TM1Constants.TABLENAME_ACCESS_INFO, table);
      table.clearRowData();
    }
  }
  public VoltTable[] run(short w_id, VoltTable items, VoltTable customerNames)
      throws VoltAbortException {
    if (items != null) {
      // check if we've already set up this partition
      voltQueueSQL(checkItemExists);
      VoltTable item = voltExecuteSQL()[0];
      if (item.getRowCount() > 0) return null;

      // now we know the partition is not loaded yet
      voltLoadTable("cluster", "database", "ITEM", items, false, false);
    }
    voltLoadTable("cluster", "database", "CUSTOMER_NAME", customerNames, false, false);
    return null;
  }
Beispiel #24
0
  @Override
  public int scan(
      String keyspace,
      String lowerBound,
      int recordCount,
      Set<String> columns,
      Vector<HashMap<String, ByteIterator>> result) {
    try {
      byte[] ks = keyspace.getBytes(UTF8);
      ClientResponse response =
          m_client.callProcedure("Scan", ks, lowerBound, lowerBound.getBytes(UTF8), recordCount);
      if (response.getStatus() != ClientResponse.SUCCESS) {
        return 1;
      }

      int nFound = 0;
      String partKey = lowerBound;
      CyclicBarrier barrier = new CyclicBarrier(2);
      result.ensureCapacity(recordCount);
      ScanCallback callback = null;
      boolean proceed = true;
      while (proceed) {
        if (response.getStatus() != ClientResponse.SUCCESS) {
          return 1;
        }
        VoltTable table = response.getResults()[0];
        nFound += table.getRowCount();
        proceed = nFound < recordCount && (partKey = nextPartitionKey(partKey)) != null;
        if (proceed) {
          barrier.reset();
          callback = new ScanCallback(barrier);
          m_client.callProcedure(callback, "Scan", ks, partKey, null, recordCount - nFound);
        }

        while (table.advanceRow()) {
          result.add(unpackRowData(table, columns));
        }

        if (proceed) {
          barrier.await();
          response = callback.response;
        }
      }
      return 0;
    } catch (Exception e) {
      e.printStackTrace();
      return 1;
    }
  }
Beispiel #25
0
 protected static void validateTableColumnOfScalarVarchar(
     VoltTable vt, int col, String[] expected) {
   assertNotNull(expected);
   assertEquals(expected.length, vt.getRowCount());
   int len = expected.length;
   for (int i = 0; i < len; i++) {
     assertTrue(vt.advanceRow());
     if (expected[i] == null) {
       String actual = vt.getString(col);
       assertTrue(vt.wasNull());
       assertEquals(null, actual);
     } else {
       assertEquals(expected[i], vt.getString(col));
     }
   }
 }
Beispiel #26
0
  protected static void validateTableColumnOfScalarFloat(VoltTable vt, int col, double[] expected) {
    assertNotNull(expected);
    assertEquals(expected.length, vt.getRowCount());
    int len = expected.length;
    for (int i = 0; i < len; i++) {
      assertTrue(vt.advanceRow());
      double actual = vt.getDouble(col);

      if (expected[i] == Double.MIN_VALUE) {
        assertTrue(vt.wasNull());
        assertEquals(null, actual);
      } else {
        assertEquals(expected[i], actual, 0.00001);
      }
    }
  }
Beispiel #27
0
  private static void validateTableColumnOfScalarVarbinary(
      VoltTable vt, int col, String[] expected) {
    assertNotNull(expected);
    assertEquals(expected.length, vt.getRowCount());
    int len = expected.length;
    for (int i = 0; i < len; i++) {
      assertTrue(vt.advanceRow());
      byte[] actual = vt.getVarbinary(col);

      if (expected[i] == null) {
        assertTrue(vt.wasNull());
        assertEquals(null, actual);
      } else {
        assertEquals(expected[i], Encoder.hexEncode(actual));
      }
    }
  }
 public static void doTestJoinAndLimitOffset(Client client)
     throws IOException, ProcCallException, InterruptedException {
   int limits[] = new int[] {1, 2, 5, 10, 12, 25, Integer.MAX_VALUE};
   int offsets[] = new int[] {0, 1, 2, 5, 10, 12, 25};
   String selecteds[] = new String[] {"*", "A.PKEY"};
   String joinops[] = new String[] {",", "LEFT JOIN", "RIGHT JOIN"};
   String conditions[] = new String[] {" A.PKEY < B.PKEY ", " A.PKEY = B.PKEY ", " A.I = B.I "};
   client.callProcedure("InsertA", -1, 0);
   for (String joinop : joinops) {
     String onwhere = "ON";
     if (joinop.equals(",")) {
       onwhere = "WHERE";
     }
     for (String selected : selecteds) {
       for (int limit : limits) {
         for (int offset : offsets) {
           for (String condition : conditions) {
             String query;
             VoltTable result;
             query = "SELECT COUNT(*) FROM A " + joinop + " B " + onwhere + condition + ";";
             result = client.callProcedure("@AdHoc", query).getResults()[0];
             long found = result.asScalarLong();
             query =
                 "SELECT "
                     + selected
                     + " FROM A "
                     + joinop
                     + " B "
                     + onwhere
                     + condition
                     + " ORDER BY A.PKEY, B.PKEY "
                     + ((limit == Integer.MAX_VALUE) ? "" : "LIMIT " + limit)
                     + ((offset == 0) ? "" : " OFFSET " + offset)
                     + ";";
             result = client.callProcedure("@AdHoc", query).getResults()[0];
             long expectedRowCount = Math.max(0, Math.min(limit, found - offset));
             assertEquals(
                 "Statement \"" + query + "\" produced wrong number of rows: ",
                 expectedRowCount,
                 result.getRowCount());
           }
         }
       }
     }
   }
 }
  @Test
  public void testCount() throws IOException, ProcCallException, InterruptedException {
    int a = 3;
    Client client = this.getClient();
    load(client);
    ClientResponse cr = client.callProcedure("TestSelect", a);
    assertEquals(Status.OK, cr.getStatus());
    VoltTable result = cr.getResults()[0];
    // make sure select just one tuple
    assertEquals(1, result.getRowCount());
    // make sure the row contents
    System.out.println("Start to compare the results...");
    // result.advanceRow();
    // check content of result
    // assertEquals(a,result.get(0, VoltType.INTEGER));

    System.out.println("Finish the comparing testCount() successfully");
  }
  @Test
  public void testCountwithduplicates()
      throws IOException, ProcCallException, InterruptedException {
    Long a = new Long(2);
    Client client = this.getClient();
    loadWithDupes(client);
    ClientResponse cr = client.callProcedure("TestSelect", a);
    assertEquals(Status.OK, cr.getStatus());
    VoltTable result = cr.getResults()[0];
    // make sure select all 5 tuples which match the query
    assertEquals(5, result.getRowCount());
    // make sure the row contents
    System.out.println("Start to compare testCountwithduplicates() the results...");
    // result.advanceRow();
    // check content of result
    // assertEquals(a,result.get(0, VoltType.INTEGER));

    System.out.println("Finish the comparing testCountwithduplicates() successfully");
  }