Search in sources :

Example 41 with ColumnInfo

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

the class UpdateSettings method getVersionResponse.

private VoltTable getVersionResponse(int version) {
    VoltTable table = new VoltTable(new ColumnInfo[] { new ColumnInfo("VERSION", VoltType.INTEGER) });
    table.addRow(version);
    return table;
}
Also used : ColumnInfo(org.voltdb.VoltTable.ColumnInfo) VoltTable(org.voltdb.VoltTable)

Example 42 with ColumnInfo

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

the class CheckUpgradePlanNT method run.

public VoltTable run(String newKitPath, String newRootPath) throws InterruptedException, ExecutionException {
    CompletableFuture<Map<Integer, ClientResponse>> pf = callNTProcedureOnAllHosts("@PrerequisitesCheckNT", newKitPath, newRootPath);
    Map<Integer, ClientResponse> cr = pf.get();
    VoltTable vt = new VoltTable(new ColumnInfo[] { new ColumnInfo("HOST_ID", VoltType.INTEGER), new ColumnInfo("CHECK_RESULT", VoltType.STRING), new ColumnInfo("WARNINGS", VoltType.STRING) });
    cr.entrySet().stream().forEach(e -> {
        String[] ret = aggregatePerHostResults(e.getValue().getResults()[0]);
        vt.addRow(e.getKey(), ret[0], ret[1]);
    });
    return vt;
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) ColumnInfo(org.voltdb.VoltTable.ColumnInfo) Map(java.util.Map) VoltTable(org.voltdb.VoltTable)

Example 43 with ColumnInfo

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

the class ExecuteTask method executePlanFragment.

@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
    if (fragmentId == SysProcFragmentId.PF_executeTask) {
        assert (params.toArray()[0] != null);
        byte[] payload = (byte[]) params.toArray()[0];
        ByteBuffer buffer = ByteBuffer.wrap(payload);
        int taskId = buffer.getInt();
        TaskType taskType = TaskType.values()[taskId];
        VoltTable result = null;
        switch(taskType) {
            // @VALIDATE_PARTITIONING is an existing system stored procedure, don't bother to provide another implementation here.
            case GET_DR_TUPLESTREAM_STATE:
                {
                    TupleStreamStateInfo stateInfo = context.getSiteProcedureConnection().getDRTupleStreamStateInfo();
                    result = createDRTupleStreamStateResultTable();
                    result.addRow(context.getHostId(), context.getPartitionId(), 0, stateInfo.partitionInfo.drId, stateInfo.partitionInfo.spUniqueId, stateInfo.partitionInfo.mpUniqueId, stateInfo.drVersion);
                    if (stateInfo.containsReplicatedStreamInfo) {
                        result.addRow(context.getHostId(), context.getPartitionId(), 1, stateInfo.replicatedInfo.drId, stateInfo.replicatedInfo.spUniqueId, stateInfo.replicatedInfo.mpUniqueId, stateInfo.drVersion);
                    }
                    break;
                }
            case SET_DR_SEQUENCE_NUMBERS:
                {
                    result = new VoltTable(STATUS_SCHEMA);
                    result.addRow(STATUS_OK);
                    long partitionSequenceNumber = buffer.getLong();
                    long mpSequenceNumber = buffer.getLong();
                    context.getSiteProcedureConnection().setDRSequenceNumbers(partitionSequenceNumber, mpSequenceNumber);
                    break;
                }
            case SET_DR_PROTOCOL_VERSION:
                {
                    result = new VoltTable(STATUS_SCHEMA);
                    result.addRow(STATUS_OK);
                    int drVersion = buffer.getInt();
                    int createStartStream = buffer.getInt();
                    if (createStartStream > 0) {
                        long uniqueId = m_runner.getUniqueId();
                        long spHandle = m_runner.getTxnState().getNotice().getSpHandle();
                        context.getSiteProcedureConnection().setDRProtocolVersion(drVersion, spHandle, uniqueId);
                    } else {
                        context.getSiteProcedureConnection().setDRProtocolVersion(drVersion);
                    }
                    break;
                }
            case SET_DRID_TRACKER_START:
                {
                    result = new VoltTable(STATUS_SCHEMA, new ColumnInfo("LOCAL_UNIQUEID", VoltType.BIGINT));
                    try {
                        byte[] paramBuf = new byte[buffer.remaining()];
                        buffer.get(paramBuf);
                        ByteArrayInputStream bais = new ByteArrayInputStream(paramBuf);
                        ObjectInputStream ois = new ObjectInputStream(bais);
                        Map<Integer, DRLogSegmentId> lastAckedIds = (Map<Integer, DRLogSegmentId>) ois.readObject();
                        for (Entry<Integer, DRLogSegmentId> e : lastAckedIds.entrySet()) {
                            if (!DRLogSegmentId.isEmptyDRId(e.getValue().drId)) {
                                int producerPartitionId = e.getKey();
                                int producerClusterId = DRLogSegmentId.getClusterIdFromDRId(e.getValue().drId);
                                DRConsumerDrIdTracker tracker = DRConsumerDrIdTracker.createPartitionTracker(e.getValue().drId, e.getValue().spUniqueId, e.getValue().mpUniqueId, producerPartitionId);
                                context.appendApplyBinaryLogTxns(producerClusterId, producerPartitionId, -1L, tracker);
                            }
                        }
                        result.addRow(STATUS_OK, m_runner.getTxnState().uniqueId);
                    } catch (Exception e) {
                        e.printStackTrace();
                        result.addRow("FAILURE");
                    }
                    break;
                }
            case RESET_DR_APPLIED_TRACKER:
                {
                    result = new VoltTable(STATUS_SCHEMA);
                    result.addRow(STATUS_OK);
                    context.resetDrAppliedTracker();
                    break;
                }
            case SET_MERGED_DRID_TRACKER:
                {
                    result = new VoltTable(STATUS_SCHEMA);
                    try {
                        byte[] paramBuf = new byte[buffer.remaining()];
                        buffer.get(paramBuf);
                        ByteArrayInputStream bais = new ByteArrayInputStream(paramBuf);
                        ObjectInputStream ois = new ObjectInputStream(bais);
                        Map<Integer, Map<Integer, DRConsumerDrIdTracker>> clusterToPartitionMap = (Map<Integer, Map<Integer, DRConsumerDrIdTracker>>) ois.readObject();
                        context.recoverWithDrAppliedTrackers(clusterToPartitionMap);
                        result.addRow(STATUS_OK);
                    } catch (Exception e) {
                        e.printStackTrace();
                        result.addRow("FAILURE");
                    }
                    break;
                }
            case INIT_DRID_TRACKER:
                {
                    result = new VoltTable(STATUS_SCHEMA);
                    try {
                        byte[] paramBuf = new byte[buffer.remaining()];
                        buffer.get(paramBuf);
                        ByteArrayInputStream bais = new ByteArrayInputStream(paramBuf);
                        ObjectInputStream ois = new ObjectInputStream(bais);
                        Map<Byte, Integer> clusterIdToPartitionCountMap = (Map<Byte, Integer>) ois.readObject();
                        context.initDRAppliedTracker(clusterIdToPartitionCountMap);
                        result.addRow(STATUS_OK);
                    } catch (Exception e) {
                        e.printStackTrace();
                        result.addRow("FAILURE");
                    }
                    break;
                }
            default:
                throw new VoltAbortException("Unable to find the task associated with the given task id");
        }
        return new DependencyPair.TableDependencyPair(DEP_executeTask, result);
    } else if (fragmentId == SysProcFragmentId.PF_executeTaskAggregate) {
        VoltTable unionTable = VoltTableUtil.unionTables(dependencies.get(DEP_executeTask));
        return new DependencyPair.TableDependencyPair(DEP_executeTaskAggregate, unionTable);
    }
    assert false;
    return null;
}
Also used : ColumnInfo(org.voltdb.VoltTable.ColumnInfo) ByteBuffer(java.nio.ByteBuffer) VoltTable(org.voltdb.VoltTable) TupleStreamStateInfo(org.voltdb.TupleStreamStateInfo) Entry(java.util.Map.Entry) ByteArrayInputStream(java.io.ByteArrayInputStream) DRConsumerDrIdTracker(org.voltdb.DRConsumerDrIdTracker) TaskType(org.voltdb.jni.ExecutionEngine.TaskType) DRLogSegmentId(org.voltdb.DRLogSegmentId) Map(java.util.Map) ObjectInputStream(java.io.ObjectInputStream) DependencyPair(org.voltdb.DependencyPair)

Example 44 with ColumnInfo

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

the class TestVoltTable method testFormattedString.

public void testFormattedString() throws JSONException, IOException {
    // Set the default timezone since we're using a timestamp type.  Eliminate test flakeyness.
    VoltDB.setDefaultTimezone();
    VoltTable table = 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
    table.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
    table.addRow(null, null, null, null, null, null, null, null, null);
    // add a row of actual data.  Hard-code the timestamp so that we can compare deterministically
    table.addRow(123, 12345, 1234567, 12345678901L, 1.234567, "aabbcc", new byte[] { 10, 26, 10 }, new TimestampType(99), new BigDecimal("123.45"));
    String formattedOutput = table.toFormattedString();
    String expectedOutput = "tinyint  smallint  integer  bigint       float     string  varbinary  timestamp                   decimal          \n" + "-------- --------- -------- ------------ --------- ------- ---------- --------------------------- -----------------\n" + "    NULL      NULL     NULL         NULL      NULL NULL    NULL       NULL                                     NULL\n" + "    NULL      NULL     NULL         NULL      NULL NULL    NULL       NULL                                     NULL\n" + "     123     12345  1234567  12345678901  1.234567 aabbcc  0A1A0A     1970-01-01 00:00:00.000099   123.450000000000\n";
    assertExpectedOutput(expectedOutput, formattedOutput);
    // fetch formatted output without column names
    formattedOutput = table.toFormattedString(false);
    expectedOutput = "    NULL      NULL     NULL         NULL      NULL NULL    NULL       NULL                                     NULL\n" + "    NULL      NULL     NULL         NULL      NULL NULL    NULL       NULL                                     NULL\n" + "     123     12345  1234567  12345678901  1.234567 aabbcc  0A1A0A     1970-01-01 00:00:00.000099   123.450000000000\n";
    assertExpectedOutput(expectedOutput, formattedOutput);
    table = new VoltTable(new ColumnInfo("bigint", VoltType.BIGINT), new ColumnInfo("geography", VoltType.GEOGRAPHY), new ColumnInfo("geography_point", VoltType.GEOGRAPHY_POINT), new ColumnInfo("timestamp", VoltType.TIMESTAMP));
    table.addRow(VoltType.NULL_BIGINT, VoltType.NULL_GEOGRAPHY, VoltType.NULL_POINT, VoltType.NULL_TIMESTAMP);
    table.addRow(null, null, null, null);
    table.addRow(123456789, new GeographyValue("POLYGON (( 1.1  9.9, " + "-9.1  9.9, " + "-9.1 -9.9, " + " 9.1 -9.9, " + " 1.1  9.9))"), new GeographyPointValue(-179.0, -89.9), new TimestampType(-1));
    formattedOutput = table.toFormattedString();
    expectedOutput = "bigint     geography                                                    geography_point       timestamp                  \n" + "---------- ------------------------------------------------------------ --------------------- ---------------------------\n" + "      NULL NULL                                                         NULL                  NULL                       \n" + "      NULL NULL                                                         NULL                  NULL                       \n" + " 123456789 POLYGON ((1.1 9.9, -9.1 9.9, -9.1 -9.9, 9.1 -9.9, 1.1 9.9))  POINT (-179.0 -89.9)  1969-12-31 23:59:59.999999 \n";
    assertExpectedOutput(expectedOutput, formattedOutput);
    // row with a polygon that max's output column width for geopgraphy column
    table.addRow(1234567890, new GeographyValue("POLYGON (( 179.1  89.9, " + "-179.1  89.9, " + "-179.1 -89.9, " + " 179.1 -89.9, " + " 179.1  89.9))"), new GeographyPointValue(-179.0, -89.9), new TimestampType(0));
    formattedOutput = table.toFormattedString();
    expectedOutput = "bigint      geography                                                                   geography_point       timestamp                  \n" + "----------- --------------------------------------------------------------------------- --------------------- ---------------------------\n" + "       NULL NULL                                                                        NULL                  NULL                       \n" + "       NULL NULL                                                                        NULL                  NULL                       \n" + "  123456789 POLYGON ((1.1 9.9, -9.1 9.9, -9.1 -9.9, 9.1 -9.9, 1.1 9.9))                 POINT (-179.0 -89.9)  1969-12-31 23:59:59.999999 \n" + " 1234567890 POLYGON ((179.1 89.9, -179.1 89.9, -179.1 -89.9, 179.1 -89.9, 179.1 89.9))  POINT (-179.0 -89.9)  1970-01-01 00:00:00.000000 \n";
    assertExpectedOutput(expectedOutput, formattedOutput);
    // row with a polygon that goes beyond max aligned display limit for polygon. This will result in
    // other columns following to appear further away from their original column
    table.addRow(12345678901L, new GeographyValue("POLYGON (( 179.12  89.9, " + "-179.12  89.9, " + "-179.1  -89.9, " + " 179.1  -89.9, " + "   0     0," + "  1.123  1.11," + " 179.12  89.9))"), new GeographyPointValue(0, 0), new TimestampType(99));
    formattedOutput = table.toFormattedString();
    expectedOutput = "bigint       geography                                                                   geography_point       timestamp                  \n" + "------------ --------------------------------------------------------------------------- --------------------- ---------------------------\n" + "        NULL NULL                                                                        NULL                  NULL                       \n" + "        NULL NULL                                                                        NULL                  NULL                       \n" + "   123456789 POLYGON ((1.1 9.9, -9.1 9.9, -9.1 -9.9, 9.1 -9.9, 1.1 9.9))                 POINT (-179.0 -89.9)  1969-12-31 23:59:59.999999 \n" + "  1234567890 POLYGON ((179.1 89.9, -179.1 89.9, -179.1 -89.9, 179.1 -89.9, 179.1 89.9))  POINT (-179.0 -89.9)  1970-01-01 00:00:00.000000 \n" + " 12345678901 POLYGON ((179.12 89.9, -179.12 89.9, -179.1 -89.9, 179.1 -89.9, 0.0 0.0, 1.123 1.11, 179.12 89.9)) POINT (0.0 0.0)       1970-01-01 00:00:00.000099 \n";
    assertExpectedOutput(expectedOutput, formattedOutput);
    // test the final one without column names
    formattedOutput = table.toFormattedString(false);
    expectedOutput = "        NULL NULL                                                                        NULL                  NULL                       \n" + "        NULL NULL                                                                        NULL                  NULL                       \n" + "   123456789 POLYGON ((1.1 9.9, -9.1 9.9, -9.1 -9.9, 9.1 -9.9, 1.1 9.9))                 POINT (-179.0 -89.9)  1969-12-31 23:59:59.999999 \n" + "  1234567890 POLYGON ((179.1 89.9, -179.1 89.9, -179.1 -89.9, 179.1 -89.9, 179.1 89.9))  POINT (-179.0 -89.9)  1970-01-01 00:00:00.000000 \n" + " 12345678901 POLYGON ((179.12 89.9, -179.12 89.9, -179.1 -89.9, 179.1 -89.9, 0.0 0.0, 1.123 1.11, 179.12 89.9)) POINT (0.0 0.0)       1970-01-01 00:00:00.000099 \n";
    assertExpectedOutput(expectedOutput, formattedOutput);
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) ColumnInfo(org.voltdb.VoltTable.ColumnInfo) TimestampType(org.voltdb.types.TimestampType) GeographyPointValue(org.voltdb.types.GeographyPointValue) BigDecimal(java.math.BigDecimal)

Example 45 with ColumnInfo

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

the class TestVoltTableUtil method testCSVTimestamp.

/**
     * Round-trip the time, see if it's still the same.
     * @throws IOException
     */
@Test
public void testCSVTimestamp() throws IOException {
    CSVWriter writer = mock(CSVWriter.class);
    ColumnInfo[] columns = new ColumnInfo[] { new ColumnInfo("", VoltType.TIMESTAMP) };
    ArrayList<VoltType> columnTypes = new ArrayList<VoltType>();
    // To make sure we have microseconds we get millisecond from current timestamp
    // and add remainder to ensure we have micros in timestamp.
    TimestampType ts = new TimestampType((System.currentTimeMillis() * 1000) + System.currentTimeMillis() % 1000);
    VoltTable vt = new VoltTable(columns);
    vt.addRow(ts);
    for (ColumnInfo ci : columns) {
        columnTypes.add(ci.type);
    }
    VoltTableUtil.toCSVWriter(writer, vt, columnTypes);
    ArgumentCaptor<String[]> captor = ArgumentCaptor.forClass(String[].class);
    verify(writer).writeNext(captor.capture());
    String[] values = captor.getValue();
    assertEquals(1, values.length);
    TimestampType newTs = new TimestampType(values[0]);
    assertEquals(ts, newTs);
}
Also used : ArrayList(java.util.ArrayList) CSVWriter(au.com.bytecode.opencsv_voltpatches.CSVWriter) ColumnInfo(org.voltdb.VoltTable.ColumnInfo) TimestampType(org.voltdb.types.TimestampType) Test(org.junit.Test)

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