예제 #1
0
  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));
    }
  }
예제 #2
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);
      }
    }
  }
예제 #3
0
  @Test
  public void testTimeZone() throws Exception {
    String[] myOptions = {"-f" + path_csv, "--reportdir=" + reportDir, "--timezone=PST", "BlAh"};
    String currentTime = "2007-09-23 10:10:10.0";
    String[] myData = {
      "1 ,1,1,11111111,first,1.10,1.11," + currentTime,
    };
    int invalidLineCnt = 0;
    int validLineCnt = 1;
    TimeZone timezone = TimeZone.getDefault();
    test_Interface(myOptions, myData, invalidLineCnt, validLineCnt);
    // Resetting the JVM TimeZone
    TimeZone.setDefault(timezone);

    VoltTable ts_table = client.callProcedure("@AdHoc", "SELECT * FROM BLAH;").getResults()[0];
    ts_table.advanceRow();
    long tableTimeCol = ts_table.getTimestampAsLong(7);
    // 2007-09-23 10:10:10.0 converted to long is 1190542210000000
    long time = 1190542210000000L;
    long diff = tableTimeCol - time;
    assertEquals(TimeUnit.MICROSECONDS.toHours(diff), 7);
  }