Search in sources :

Example 16 with ColumnInfo

use of org.voltdb.VoltTable.ColumnInfo in project voltdb by VoltDB.

the class TestClientInterface method testLoadSinglePartTableInsert.

@Test
public void testLoadSinglePartTableInsert() throws Exception {
    VoltTable table = new VoltTable(new ColumnInfo("i", VoltType.INTEGER));
    table.addRow(1);
    byte[] partitionParam = { 0, 0, 0, 0, 0, 0, 0, 4 };
    ByteBuffer msg = createMsg("@LoadSinglepartitionTable", partitionParam, "a", (byte) 0, table);
    StoredProcedureInvocation invocation = readAndCheck(msg, "@LoadSinglepartitionTable", partitionParam, false, true).getStoredProcedureInvocation();
    assertEquals((byte) 0, invocation.getParameterAtIndex(2));
}
Also used : ColumnInfo(org.voltdb.VoltTable.ColumnInfo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 17 with ColumnInfo

use of org.voltdb.VoltTable.ColumnInfo in project voltdb by VoltDB.

the class TestVoltTable method testJSONRoundTrip.

@SuppressWarnings("deprecation")
public void testJSONRoundTrip() throws JSONException, IOException {
    VoltTable t1 = new VoltTable(new ColumnInfo("tinyint", VoltType.TINYINT), new ColumnInfo("smallint", VoltType.SMALLINT), new ColumnInfo("integer", VoltType.INTEGER), new ColumnInfo("bigint", VoltType.BIGINT), new ColumnInfo("float", VoltType.FLOAT), new ColumnInfo("string", VoltType.STRING), new ColumnInfo("varbinary", VoltType.VARBINARY), new ColumnInfo("timestamp", VoltType.TIMESTAMP), new ColumnInfo("decimal", VoltType.DECIMAL));
    // add a row of nulls the hard way
    t1.addRow(VoltType.NULL_TINYINT, VoltType.NULL_SMALLINT, VoltType.NULL_INTEGER, VoltType.NULL_BIGINT, VoltType.NULL_FLOAT, VoltType.NULL_STRING_OR_VARBINARY, VoltType.NULL_STRING_OR_VARBINARY, VoltType.NULL_TIMESTAMP, VoltType.NULL_DECIMAL);
    // add a row of nulls the easy way
    t1.addRow(null, null, null, null, null, null, null, null, null);
    // add a row with NaN
    t1.addRow(null, null, null, null, Double.NaN, null, null, null, null);
    // add a row with +inf
    t1.addRow(null, null, null, null, Double.POSITIVE_INFINITY, null, null, null, null);
    // add a row with all defaults
    t1.addRow(VoltType.NULL_TINYINT, VoltType.NULL_SMALLINT, VoltType.NULL_INTEGER, VoltType.NULL_BIGINT, VoltType.NULL_FLOAT, VoltType.NULL_STRING_OR_VARBINARY, VoltType.NULL_STRING_OR_VARBINARY, VoltType.NULL_TIMESTAMP, VoltType.NULL_DECIMAL);
    // add a row of actual data
    t1.addRow(123, 12345, 1234567, 12345678901L, 1.234567, "aabbcc", new byte[] { 10, 26, 10 }, new TimestampType(System.currentTimeMillis()), new BigDecimal("123.45"));
    String json = t1.toJSONString();
    VoltTable t2 = VoltTable.fromJSONString(json);
    assertTrue(t1.equals(t2));
}
Also used : ColumnInfo(org.voltdb.VoltTable.ColumnInfo) TimestampType(org.voltdb.types.TimestampType) BigDecimal(java.math.BigDecimal)

Example 18 with ColumnInfo

use of org.voltdb.VoltTable.ColumnInfo in project voltdb by VoltDB.

the class TestVoltTable method testGeographies.

public void testGeographies() {
    VoltTable vt = new VoltTable(new ColumnInfo("gg", VoltType.GEOGRAPHY));
    addAllPrimitives(vt, new Class[] { GeographyValue.class });
    VoltTable vtCopy = roundTrip(vt);
    assertEquals(2, vt.getRowCount());
    assertEquals(2, vtCopy.getRowCount());
    assertTrue(vt.advanceRow());
    assertTrue(vtCopy.advanceRow());
    assertNull(vt.getGeographyValue(0));
    assertNull(vtCopy.getGeographyValue(0));
    assertNull(vt.get(0, VoltType.GEOGRAPHY));
    assertTrue(vt.wasNull());
    assertTrue(vtCopy.wasNull());
    assertTrue(vt.advanceRow());
    assertTrue(vtCopy.advanceRow());
    String wkt = GEOG_VALUE.toString();
    assertEquals(wkt, vt.getGeographyValue(0).toString());
    assertEquals(wkt, vtCopy.getGeographyValue(0).toString());
    assertEquals(wkt, vt.getGeographyValue("gg").toString());
    assertEquals(wkt, vt.get(0, VoltType.GEOGRAPHY).toString());
    byte[] raw = vt.getRaw(0);
    // Raw bytes does not include the length prefix
    assertEquals(GEOG_VALUE.getLengthInBytes(), raw.length - 4);
    byte[] rawCopy = vtCopy.getRaw(0);
    assertEquals(raw.length, rawCopy.length);
    for (int i = 0; i < rawCopy.length; ++i) {
        assertEquals("raw geography not equal to copy at byte " + i, raw[i], rawCopy[i]);
    }
    assertFalse(vt.advanceRow());
    assertFalse(vtCopy.advanceRow());
}
Also used : ColumnInfo(org.voltdb.VoltTable.ColumnInfo)

Example 19 with ColumnInfo

use of org.voltdb.VoltTable.ColumnInfo in project voltdb by VoltDB.

the class TestVoltTable method testClone.

public void testClone() {
    VoltTable item_data_template = new VoltTable(new ColumnInfo("i_name", VoltType.STRING), new ColumnInfo("s_quantity", VoltType.BIGINT), new ColumnInfo("brand_generic", VoltType.STRING), new ColumnInfo("i_price", VoltType.FLOAT), new ColumnInfo("ol_amount", VoltType.FLOAT));
    VoltTable item_data = item_data_template.clone(1024);
    assertEquals(5, item_data.getColumnCount());
    assertEquals("i_name", item_data.getColumnName(0));
    assertEquals("s_quantity", item_data.getColumnName(1));
    assertEquals("brand_generic", item_data.getColumnName(2));
    assertEquals("i_price", item_data.getColumnName(3));
    assertEquals("ol_amount", item_data.getColumnName(4));
    assertEquals(VoltType.STRING, item_data.getColumnType(0));
    assertEquals(VoltType.BIGINT, item_data.getColumnType(1));
    assertEquals(VoltType.STRING, item_data.getColumnType(2));
    assertEquals(VoltType.FLOAT, item_data.getColumnType(3));
    assertEquals(VoltType.FLOAT, item_data.getColumnType(4));
    item_data.addRow("asdfsdgfsdg", 123L, "a", 45.0d, 656.2d);
}
Also used : ColumnInfo(org.voltdb.VoltTable.ColumnInfo)

Example 20 with ColumnInfo

use of org.voltdb.VoltTable.ColumnInfo in project voltdb by VoltDB.

the class TestVoltTable method testRowGet.

public void testRowGet() {
    byte b1 = (byte) 1;
    short s1 = (short) 2;
    int i1 = 3;
    long l1 = Long.MIN_VALUE + 1;
    double f1 = 3.5;
    String S1 = "A";
    TimestampType d1 = new TimestampType(0);
    BigDecimal B1 = new BigDecimal(7654321).setScale(VoltDecimalHelper.kDefaultScale);
    // create a table with one column per supported type with NULLS on the
    // left to right diagonal.
    // tinyint is intentionally first AND last to test that wasNull is
    // correctly cleared by the
    // the next-to-last instance and re-initialized by tinyint.
    Object[] content = { b1, S1, i1, l1, f1, s1, d1, B1, b1 };
    Object[] nulls = { VoltType.NULL_TINYINT, VoltType.NULL_STRING_OR_VARBINARY, VoltType.NULL_INTEGER, VoltType.NULL_BIGINT, VoltType.NULL_FLOAT, VoltType.NULL_SMALLINT, VoltType.NULL_TIMESTAMP, VoltType.NULL_DECIMAL, VoltType.NULL_TINYINT };
    VoltType[] types = { VoltType.TINYINT, VoltType.STRING, VoltType.INTEGER, VoltType.BIGINT, VoltType.FLOAT, VoltType.SMALLINT, VoltType.TIMESTAMP, VoltType.DECIMAL, VoltType.TINYINT };
    VoltTable tt = new VoltTable(new ColumnInfo("tinyint", types[0]), new ColumnInfo("string", types[1]), new ColumnInfo("integer", types[2]), new ColumnInfo("bigint", types[3]), new ColumnInfo("float", types[4]), new ColumnInfo("smallint", types[5]), new ColumnInfo("timestamp", types[6]), new ColumnInfo("decimal", types[7]), new ColumnInfo("tinyint", types[0]));
    for (int i = 0; i < content.length; ++i) {
        Object[] vals = new Object[content.length];
        ;
        for (int k = 0; k < content.length; k++) {
            if (i == k)
                vals[k] = nulls[k];
            else
                vals[k] = content[k];
        }
        System.out.println("Adding row: " + i);
        tt.addRow(vals);
    }
    // now iterate all the fields in the table and verify that row.get(idx,
    // type)
    // works and that the wasNull state is correctly set and cleared.
    System.out.println(tt);
    int rowcounter = 0;
    while (tt.advanceRow()) {
        for (int k = 0; k < content.length; k++) {
            System.out.println("verifying row:" + rowcounter + " col:" + k);
            if (rowcounter == k) {
                boolean result = comparisonHelper(nulls[k], tt.get(k, types[k]), types[k]);
                assertTrue(result);
                assertTrue(tt.wasNull());
            } else {
                Object got = tt.get(k, types[k]);
                System.out.println("Type: " + types[k]);
                System.out.println("Expecting: " + content[k]);
                System.out.println("Got: " + got);
                assertTrue(comparisonHelper(content[k], got, types[k]));
                assertFalse(tt.wasNull());
            }
        }
        rowcounter++;
    }
    assertEquals(rowcounter, content.length);
}
Also used : ColumnInfo(org.voltdb.VoltTable.ColumnInfo) BigDecimal(java.math.BigDecimal) TimestampType(org.voltdb.types.TimestampType)

Aggregations

ColumnInfo (org.voltdb.VoltTable.ColumnInfo)84 VoltTable (org.voltdb.VoltTable)40 Client (org.voltdb.client.Client)17 HashMap (java.util.HashMap)10 ByteBuffer (java.nio.ByteBuffer)6 DependencyPair (org.voltdb.DependencyPair)6 BigDecimal (java.math.BigDecimal)5 ArrayList (java.util.ArrayList)5 TimestampType (org.voltdb.types.TimestampType)5 Test (org.junit.Test)4 CSVWriter (au.com.bytecode.opencsv_voltpatches.CSVWriter)2 Map (java.util.Map)2 JSONObject (org.json_voltpatches.JSONObject)2 CatalogContext (org.voltdb.CatalogContext)2 CatalogSpecificPlanner (org.voltdb.CatalogSpecificPlanner)2 GeographyPointValue (org.voltdb.types.GeographyPointValue)2 GeographyValue (org.voltdb.types.GeographyValue)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1