java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
@Test(timeout = 100000)
  public void testTimestampColumns() throws Exception {
    Schema schema = createSchemaWithTimestampColumns();
    syncClient.createTable(tableName, schema, getBasicCreateTableOptions());

    List<Long> timestamps = new ArrayList<>();

    KuduSession session = syncClient.newSession();
    KuduTable table = syncClient.openTable(tableName);
    long lastTimestamp = 0;
    for (int i = 0; i < 100; i++) {
      Insert insert = table.newInsert();
      PartialRow row = insert.getRow();
      long timestamp = System.currentTimeMillis() * 1000;
      while(timestamp == lastTimestamp) {
        timestamp = System.currentTimeMillis() * 1000;
      }
      timestamps.add(timestamp);
      row.addLong("key", timestamp);
      if (i % 2 == 1) {
        row.addLong("c1", timestamp);
      }
      session.apply(insert);
      if (i % 50 == 0) {
        session.flush();
      }
      lastTimestamp = timestamp;
    }
    session.flush();

    List<String> rowStrings = scanTableToStrings(table);
    assertEquals(100, rowStrings.size());
    for (int i = 0; i < rowStrings.size(); i++) {
      StringBuilder expectedRow = new StringBuilder();
      expectedRow.append(String.format("UNIXTIME_MICROS key=%s, UNIXTIME_MICROS c1=",
          TimestampUtil.timestampToString(timestamps.get(i))));
      if (i % 2 == 1) {
        expectedRow.append(TimestampUtil.timestampToString(timestamps.get(i)));
      } else {
        expectedRow.append("NULL");
      }
      assertEquals(expectedRow.toString(), rowStrings.get(i));
    }
  }
/**
   * Test inserting and retrieving timestamp columns.
   */
Test inserting and retrieving timestamp columns.
Test inserting and retrieving timestamp columns .
@Test(timeout = 100000)
  public void testTimestampColumns() throws Exception {
    Schema schema = createSchemaWithTimestampColumns();
    syncClient.createTable(tableName, schema, getBasicCreateTableOptions());
    List<Long> timestamps = new ArrayList<>();
    KuduSession session = syncClient.newSession();
    KuduTable table = syncClient.openTable(tableName);
    long lastTimestamp = 0;
    for (int i = 0; i < 100; i++) {
      Insert insert = table.newInsert();
      PartialRow row = insert.getRow();
      long timestamp = System.currentTimeMillis() * 1000;
      while(timestamp == lastTimestamp) {
        timestamp = System.currentTimeMillis() * 1000;
      }
      timestamps.add(timestamp);
      row.addLong("key", timestamp);
      if (i % 2 == 1) {
        row.addLong("c1", timestamp);
      }
      session.apply(insert);
      if (i % 50 == 0) {
        session.flush();
      }
      lastTimestamp = timestamp;
    }
    session.flush();
    List<String> rowStrings = scanTableToStrings(table);
    assertEquals(100, rowStrings.size());
    for (int i = 0; i < rowStrings.size(); i++) {
      StringBuilder expectedRow = new StringBuilder();
      expectedRow.append(String.format("UNIXTIME_MICROS key=%s, UNIXTIME_MICROS c1=",
          TimestampUtil.timestampToString(timestamps.get(i))));
      if (i % 2 == 1) {
        expectedRow.append(TimestampUtil.timestampToString(timestamps.get(i)));
      } else {
        expectedRow.append("NULL");
      }
      assertEquals(expectedRow.toString(), rowStrings.get(i));
    }
  }
@ Test ( timeout = 100000 ) public void testTimestampColumns ( ) throws Exception { Schema schema = createSchemaWithTimestampColumns ( ) ; syncClient . createTable ( tableName , schema , getBasicCreateTableOptions ( ) ) ; List < Long > timestamps = new ArrayList < > ( ) ; KuduSession session = syncClient . newSession ( ) ; KuduTable table = syncClient . openTable ( tableName ) ; long lastTimestamp = 0 ; for ( int i = 0 ; i < 100 ; i ++ ) { Insert insert = table . newInsert ( ) ; PartialRow row = insert . getRow ( ) ; long timestamp = System . currentTimeMillis ( ) * 1000 ; while ( timestamp == lastTimestamp ) { timestamp = System . currentTimeMillis ( ) * 1000 ; } timestamps . add ( timestamp ) ; row . addLong ( "key" , timestamp ) ; if ( i % 2 == 1 ) { row . addLong ( "c1" , timestamp ) ; } session . apply ( insert ) ; if ( i % 50 == 0 ) { session . flush ( ) ; } lastTimestamp = timestamp ; } session . flush ( ) ; List < String > rowStrings = scanTableToStrings ( table ) ; assertEquals ( 100 , rowStrings . size ( ) ) ; for ( int i = 0 ; i < rowStrings . size ( ) ; i ++ ) { StringBuilder expectedRow = new StringBuilder ( ) ; expectedRow . append ( String . format ( "UNIXTIME_MICROS key=%s, UNIXTIME_MICROS c1=" , TimestampUtil . timestampToString ( timestamps . get ( i ) ) ) ) ; if ( i % 2 == 1 ) { expectedRow . append ( TimestampUtil . timestampToString ( timestamps . get ( i ) ) ) ; } else { expectedRow . append ( "NULL" ) ; } assertEquals ( expectedRow . toString ( ) , rowStrings . get ( i ) ) ; } }
Test inserting and retrieving timestamp columns.
Test inserting and retrieving timestamp columns .