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

    KuduSession session = syncClient.newSession();
    KuduTable table = syncClient.openTable(tableName);

    // Verify ColumnTypeAttributes
    assertEquals(DecimalUtil.MAX_DECIMAL128_PRECISION,
        table.getSchema().getColumn("c1").getTypeAttributes().getPrecision());

    for (int i = 0; i < 9; i++) {
      Insert insert = table.newInsert();
      PartialRow row = insert.getRow();
      row.addDecimal("key", BigDecimal.valueOf(i));
      if (i % 2 == 1) {
        row.addDecimal("c1", BigDecimal.valueOf(i));
      }
      session.apply(insert);
    }
    session.flush();

    List<String> rowStrings = scanTableToStrings(table);
    assertEquals(9, rowStrings.size());
    for (int i = 0; i < rowStrings.size(); i++) {
      StringBuilder expectedRow = new StringBuilder();
      expectedRow.append(String.format("DECIMAL key(18, 0)=%s, DECIMAL c1(38, 0)=", String.valueOf(i)));
      if (i % 2 == 1) {
        expectedRow.append(String.valueOf(i));
      } else {
        expectedRow.append("NULL");
      }
      assertEquals(expectedRow.toString(), rowStrings.get(i));
    }
  }
/**
   * Test inserting and retrieving decimal columns.
   */
Test inserting and retrieving decimal columns.
Test inserting and retrieving decimal columns .
@Test(timeout = 100000)
  public void testDecimalColumns() throws Exception {
    Schema schema = createSchemaWithDecimalColumns();
    syncClient.createTable(tableName, schema, getBasicCreateTableOptions());
    KuduSession session = syncClient.newSession();
    KuduTable table = syncClient.openTable(tableName);
    assertEquals(DecimalUtil.MAX_DECIMAL128_PRECISION,
        table.getSchema().getColumn("c1").getTypeAttributes().getPrecision());
    for (int i = 0; i < 9; i++) {
      Insert insert = table.newInsert();
      PartialRow row = insert.getRow();
      row.addDecimal("key", BigDecimal.valueOf(i));
      if (i % 2 == 1) {
        row.addDecimal("c1", BigDecimal.valueOf(i));
      }
      session.apply(insert);
    }
    session.flush();
    List<String> rowStrings = scanTableToStrings(table);
    assertEquals(9, rowStrings.size());
    for (int i = 0; i < rowStrings.size(); i++) {
      StringBuilder expectedRow = new StringBuilder();
      expectedRow.append(String.format("DECIMAL key(18, 0)=%s, DECIMAL c1(38, 0)=", String.valueOf(i)));
      if (i % 2 == 1) {
        expectedRow.append(String.valueOf(i));
      } else {
        expectedRow.append("NULL");
      }
      assertEquals(expectedRow.toString(), rowStrings.get(i));
    }
  }
@ Test ( timeout = 100000 ) public void testDecimalColumns ( ) throws Exception { Schema schema = createSchemaWithDecimalColumns ( ) ; syncClient . createTable ( tableName , schema , getBasicCreateTableOptions ( ) ) ; KuduSession session = syncClient . newSession ( ) ; KuduTable table = syncClient . openTable ( tableName ) ; assertEquals ( DecimalUtil . MAX_DECIMAL128_PRECISION , table . getSchema ( ) . getColumn ( "c1" ) . getTypeAttributes ( ) . getPrecision ( ) ) ; for ( int i = 0 ; i < 9 ; i ++ ) { Insert insert = table . newInsert ( ) ; PartialRow row = insert . getRow ( ) ; row . addDecimal ( "key" , BigDecimal . valueOf ( i ) ) ; if ( i % 2 == 1 ) { row . addDecimal ( "c1" , BigDecimal . valueOf ( i ) ) ; } session . apply ( insert ) ; } session . flush ( ) ; List < String > rowStrings = scanTableToStrings ( table ) ; assertEquals ( 9 , rowStrings . size ( ) ) ; for ( int i = 0 ; i < rowStrings . size ( ) ; i ++ ) { StringBuilder expectedRow = new StringBuilder ( ) ; expectedRow . append ( String . format ( "DECIMAL key(18, 0)=%s, DECIMAL c1(38, 0)=" , String . valueOf ( i ) ) ) ; if ( i % 2 == 1 ) { expectedRow . append ( String . valueOf ( i ) ) ; } else { expectedRow . append ( "NULL" ) ; } assertEquals ( expectedRow . toString ( ) , rowStrings . get ( i ) ) ; } }
Test inserting and retrieving decimal columns.
Test inserting and retrieving decimal columns .
// Verify ColumnTypeAttributes