Exemplo n.º 1
0
 public void testAggregatesOnEmptyTable() throws IOException, ProcCallException {
   String[] aggs = {"count", "sum", "min", "max"};
   String[] tables = {"P1", "R1"};
   for (String table : tables) {
     Client client = getClient();
     for (int i = 0; i < aggs.length; ++i) {
       String query = String.format("select %s(%s.NUM) from %s", aggs[i], table, table);
       VoltTable[] results = client.callProcedure("@AdHoc", query).getResults();
       if (aggs[i].equals("count")) {
         assertEquals(0, results[0].asScalarLong());
       } else {
         final VoltTableRow row = results[0].fetchRow(0);
         row.get(0, results[0].getColumnType(0));
         if (!isHSQL()) {
           assertTrue(row.wasNull());
         }
       }
     }
     // Do avg separately since the column is a float and makes
     // asScalarLong() unhappy
     String query = String.format("select avg(%s.NUM) from %s", table, table);
     VoltTable[] results = client.callProcedure("@AdHoc", query).getResults();
     results[0].advanceRow();
     @SuppressWarnings("unused")
     final double value = ((Number) results[0].get(0, results[0].getColumnType(0))).doubleValue();
     if (!isHSQL()) {
       assertTrue(results[0].wasNull());
     }
   }
 }
  public VoltTable[] run(long rowid, long ignore) {
    @SuppressWarnings("deprecation")
    long txid = getVoltPrivateRealTransactionIdDontUseMe();

    // Critical for proper determinism: get a cluster-wide consistent Random instance
    Random rand = new Random(txid);

    // Check if the record exists first
    voltQueueSQL(check, rowid);

    // Grab resultset for possibly existing record
    VoltTable item = voltExecuteSQL()[0];

    // If the record exist perform an update or delete
    if (item.getRowCount() > 0) {
      // Randomly decide whether to delete (or update) the record
      if (rand.nextBoolean()) {
        voltQueueSQL(delete, rowid);
        // Export deletion
        VoltTableRow row = item.fetchRow(0);
        voltQueueSQL(
            export,
            txid,
            rowid,
            row.get(1, VoltType.TINYINT),
            row.get(2, VoltType.TINYINT),
            row.get(3, VoltType.TINYINT),
            row.get(4, VoltType.SMALLINT),
            row.get(5, VoltType.SMALLINT),
            row.get(6, VoltType.INTEGER),
            row.get(7, VoltType.INTEGER),
            row.get(8, VoltType.BIGINT),
            row.get(9, VoltType.BIGINT),
            row.get(10, VoltType.TIMESTAMP),
            row.get(11, VoltType.TIMESTAMP),
            row.get(12, VoltType.FLOAT),
            row.get(13, VoltType.FLOAT),
            row.get(14, VoltType.DECIMAL),
            row.get(15, VoltType.DECIMAL),
            row.get(16, VoltType.STRING),
            row.get(17, VoltType.STRING),
            row.get(18, VoltType.STRING),
            row.get(19, VoltType.STRING),
            row.get(20, VoltType.STRING),
            row.get(21, VoltType.STRING));
      } else {
        SampleRecord record = new SampleRecord(rowid, rand);
        voltQueueSQL(
            update,
            record.type_null_tinyint,
            record.type_not_null_tinyint,
            record.type_null_smallint,
            record.type_not_null_smallint,
            record.type_null_integer,
            record.type_not_null_integer,
            record.type_null_bigint,
            record.type_not_null_bigint,
            record.type_null_timestamp,
            record.type_not_null_timestamp,
            record.type_null_float,
            record.type_not_null_float,
            record.type_null_decimal,
            record.type_not_null_decimal,
            record.type_null_varchar25,
            record.type_not_null_varchar25,
            record.type_null_varchar128,
            record.type_not_null_varchar128,
            record.type_null_varchar1024,
            record.type_not_null_varchar1024,
            rowid);
      }
    } else {
      // Insert a new record
      SampleRecord record = new SampleRecord(rowid, rand);
      voltQueueSQL(
          insert,
          rowid,
          record.rowid_group,
          record.type_null_tinyint,
          record.type_not_null_tinyint,
          record.type_null_smallint,
          record.type_not_null_smallint,
          record.type_null_integer,
          record.type_not_null_integer,
          record.type_null_bigint,
          record.type_not_null_bigint,
          record.type_null_timestamp,
          record.type_not_null_timestamp,
          record.type_null_float,
          record.type_not_null_float,
          record.type_null_decimal,
          record.type_not_null_decimal,
          record.type_null_varchar25,
          record.type_not_null_varchar25,
          record.type_null_varchar128,
          record.type_not_null_varchar128,
          record.type_null_varchar1024,
          record.type_not_null_varchar1024);
    }

    // Execute last SQL batch
    voltExecuteSQL(true);

    // Retun to caller
    return null;
  }