Search in sources :

Example 6 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class VoltDB method crashLocalVoltDB.

/**
     * Exit the process with an error message, optionally with a stack trace.
     */
public static void crashLocalVoltDB(String errMsg, boolean stackTrace, Throwable thrown) {
    if (exitAfterMessage) {
        System.err.println(errMsg);
        VoltDB.exit(-1);
    }
    try {
        OnDemandBinaryLogger.flush();
    } catch (Throwable e) {
    }
    /*
         * InvocationTargetException suppresses information about the cause, so unwrap until
         * we get to the root cause
         */
    while (thrown instanceof InvocationTargetException) {
        thrown = ((InvocationTargetException) thrown).getCause();
    }
    // for test code
    wasCrashCalled = true;
    crashMessage = errMsg;
    if (ignoreCrash) {
        throw new AssertionError("Faux crash of VoltDB successful.");
    }
    if (CoreUtils.isJunitTest()) {
        VoltLogger log = new VoltLogger("HOST");
        log.warn("Declining to drop a crash file during a junit test.");
    }
    // end test code
    // send a snmp trap crash notification
    sendCrashSNMPTrap(errMsg);
    // is called in
    try {
        // prints a message to stdout
        try {
            // we don't expect this to ever fail, but if it does, skip to dying immediately
            if (!turnOffClientInterface()) {
                // this will jump to the finally block and die faster
                return;
            }
            // Flush trace files
            try {
                VoltTrace.closeAllAndShutdown(new File(instance().getVoltDBRootPath(), "trace_logs").getAbsolutePath(), TimeUnit.SECONDS.toMillis(10));
            } catch (IOException e) {
            }
            // Even if the logger is null, don't stop.  We want to log the stack trace and
            // any other pertinent information to a .dmp file for crash diagnosis
            List<String> currentStacktrace = new ArrayList<>();
            currentStacktrace.add("Stack trace from crashLocalVoltDB() method:");
            // Create a special dump file to hold the stack trace
            try {
                TimestampType ts = new TimestampType(new java.util.Date());
                CatalogContext catalogContext = VoltDB.instance().getCatalogContext();
                String root = catalogContext != null ? VoltDB.instance().getVoltDBRootPath() + File.separator : "";
                PrintWriter writer = new PrintWriter(root + "voltdb_crash" + ts.toString().replace(' ', '-') + ".txt");
                writer.println("Time: " + ts);
                writer.println("Message: " + errMsg);
                writer.println();
                writer.println("Platform Properties:");
                PlatformProperties pp = PlatformProperties.getPlatformProperties();
                String[] lines = pp.toLogLines(instance().getVersionString()).split("\n");
                for (String line : lines) {
                    writer.println(line.trim());
                }
                if (thrown != null) {
                    writer.println();
                    writer.println("****** Exception Thread ****** ");
                    thrown.printStackTrace(writer);
                }
                printStackTraces(writer, currentStacktrace);
                writer.close();
            } catch (Throwable err) {
                // shouldn't fail, but..
                err.printStackTrace();
            }
            VoltLogger log = null;
            try {
                log = new VoltLogger("HOST");
            } catch (RuntimeException rt_ex) {
            /* ignore */
            }
            if (log != null) {
                log.fatal(errMsg);
                if (thrown != null) {
                    if (stackTrace) {
                        log.fatal("Fatal exception", thrown);
                    } else {
                        log.fatal(thrown.toString());
                    }
                } else {
                    if (stackTrace) {
                        for (String currentStackElem : currentStacktrace) {
                            log.fatal(currentStackElem);
                        }
                    }
                }
            } else {
                System.err.println(errMsg);
                if (thrown != null) {
                    if (stackTrace) {
                        thrown.printStackTrace();
                    } else {
                        System.err.println(thrown.toString());
                    }
                } else {
                    if (stackTrace) {
                        for (String currentStackElem : currentStacktrace) {
                            System.err.println(currentStackElem);
                        }
                    }
                }
            }
        } finally {
            System.err.println("VoltDB has encountered an unrecoverable error and is exiting.");
            System.err.println("The log may contain additional information.");
        }
    } finally {
        ShutdownHooks.useOnlyCrashHooks();
        System.exit(-1);
    }
}
Also used : Date(java.util.Date) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) VoltLogger(org.voltcore.logging.VoltLogger) TimestampType(org.voltdb.types.TimestampType) PlatformProperties(org.voltdb.utils.PlatformProperties) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 7 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class VoltTable method toString.

/**
     * Returns a {@link java.lang.String String} representation of this table.
     * Resulting string will contain schema and all data and will be formatted.
     * @return a {@link java.lang.String String} representation of this table.
     */
@Override
public String toString() {
    assert (verifyTableInvariants());
    StringBuilder buffer = new StringBuilder();
    // commented out code to print byte by byte content
    /*for (int i = 0; i < m_buffer.limit(); i++) {
            byte b = m_buffer.get(i);
            char c = (char) b;
            if (Character.isLetterOrDigit(c))
                buffer.append(c);
            else
                buffer.append("[").append(b).append("]");
            buffer.append(" ");
        }
        buffer.append("\n");*/
    buffer.append(" header size: ").append(m_buffer.getInt(0)).append("\n");
    byte statusCode = m_buffer.get(4);
    buffer.append(" status code: ").append(statusCode);
    short colCount = m_buffer.getShort(5);
    buffer.append(" column count: ").append(colCount).append("\n");
    assert (colCount == m_colCount);
    buffer.append(" cols ");
    for (int i = 0; i < colCount; i++) buffer.append("(").append(getColumnName(i)).append(":").append(getColumnType(i).name()).append("), ");
    buffer.append("\n");
    buffer.append(" rows -\n");
    VoltTableRow r = cloneRow();
    r.resetRowPosition();
    while (r.advanceRow()) {
        buffer.append("  ");
        for (int i = 0; i < m_colCount; i++) {
            switch(getColumnType(i)) {
                case TINYINT:
                case SMALLINT:
                case INTEGER:
                case BIGINT:
                    long lval = r.getLong(i);
                    if (r.wasNull())
                        buffer.append("NULL");
                    else
                        buffer.append(lval);
                    break;
                case FLOAT:
                    double dval = r.getDouble(i);
                    if (r.wasNull())
                        buffer.append("NULL");
                    else
                        buffer.append(dval);
                    break;
                case TIMESTAMP:
                    TimestampType tstamp = r.getTimestampAsTimestamp(i);
                    if (r.wasNull()) {
                        buffer.append("NULL");
                        assert (tstamp == null);
                    } else {
                        buffer.append(tstamp);
                    }
                    break;
                case STRING:
                    String string = r.getString(i);
                    if (r.wasNull()) {
                        buffer.append("NULL");
                        assert (string == null);
                    } else {
                        buffer.append(string);
                    }
                    break;
                case VARBINARY:
                    byte[] bin = r.getVarbinary(i);
                    if (r.wasNull()) {
                        buffer.append("NULL");
                        assert (bin == null);
                    } else {
                        buffer.append(varbinaryToPrintableString(bin));
                    }
                    break;
                case DECIMAL:
                    BigDecimal bd = r.getDecimalAsBigDecimal(i);
                    if (r.wasNull()) {
                        buffer.append("NULL");
                        assert (bd == null);
                    } else {
                        buffer.append(bd.toString());
                    }
                    break;
                case GEOGRAPHY_POINT:
                    GeographyPointValue pt = r.getGeographyPointValue(i);
                    if (r.wasNull()) {
                        buffer.append("NULL");
                    } else {
                        buffer.append(pt.toString());
                    }
                    break;
                case GEOGRAPHY:
                    GeographyValue gv = r.getGeographyValue(i);
                    if (r.wasNull()) {
                        buffer.append("NULL");
                    } else {
                        buffer.append(gv.toString());
                    }
                    break;
                default:
                    // should not get here ever
                    throw new IllegalStateException("Table column had unexpected type.");
            }
            if (i < m_colCount - 1) {
                buffer.append(",");
            }
        }
        buffer.append("\n");
    }
    assert (verifyTableInvariants());
    return buffer.toString();
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) JSONString(org.json_voltpatches.JSONString) BigDecimal(java.math.BigDecimal) TimestampType(org.voltdb.types.TimestampType) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 8 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class ExportOnServerVerifier method verifyRow.

public static ValidationErr verifyRow(String[] row) throws ValidationErr {
    if (row.length < 29) {
        System.err.println("ERROR: Unexpected number of columns for the following row:\n\t Expected 29, Found: " + row.length + "Row:" + Arrays.toString(row));
        return new ValidationErr("number of columns", row.length, 29);
    }
    // col offset is always pre-incremented.
    int col = 5;
    // col 6
    Long txnid = Long.parseLong(row[++col]);
    // col 7
    Long rowid = Long.parseLong(row[++col]);
    // matches VoltProcedure.getSeededRandomNumberGenerator()
    Random prng = new Random(txnid);
    SampleRecord valid = new SampleRecord(rowid, prng);
    // col 8
    Byte rowid_group = Byte.parseByte(row[++col]);
    if (rowid_group != valid.rowid_group)
        return error("rowid_group invalid", rowid_group, valid.rowid_group);
    // col 9
    Byte type_null_tinyint = row[++col].equals("NULL") ? null : Byte.valueOf(row[col]);
    if ((!(type_null_tinyint == null && valid.type_null_tinyint == null)) && (!type_null_tinyint.equals(valid.type_null_tinyint)))
        return error("type_not_null_tinyint", type_null_tinyint, valid.type_null_tinyint);
    // col 10
    Byte type_not_null_tinyint = Byte.valueOf(row[++col]);
    if (!type_not_null_tinyint.equals(valid.type_not_null_tinyint))
        return error("type_not_null_tinyint", type_not_null_tinyint, valid.type_not_null_tinyint);
    // col 11
    Short type_null_smallint = row[++col].equals("NULL") ? null : Short.valueOf(row[col]);
    if ((!(type_null_smallint == null && valid.type_null_smallint == null)) && (!type_null_smallint.equals(valid.type_null_smallint)))
        return error("type_null_smallint", type_null_smallint, valid.type_null_smallint);
    // col 12
    Short type_not_null_smallint = Short.valueOf(row[++col]);
    if (!type_not_null_smallint.equals(valid.type_not_null_smallint))
        return error("type_null_smallint", type_not_null_smallint, valid.type_not_null_smallint);
    // col 13
    Integer type_null_integer = row[++col].equals("NULL") ? null : Integer.valueOf(row[col]);
    if ((!(type_null_integer == null && valid.type_null_integer == null)) && (!type_null_integer.equals(valid.type_null_integer)))
        return error("type_null_integer", type_null_integer, valid.type_null_integer);
    // col 14
    Integer type_not_null_integer = Integer.valueOf(row[++col]);
    if (!type_not_null_integer.equals(valid.type_not_null_integer))
        return error("type_not_null_integer", type_not_null_integer, valid.type_not_null_integer);
    // col 15
    Long type_null_bigint = row[++col].equals("NULL") ? null : Long.valueOf(row[col]);
    if ((!(type_null_bigint == null && valid.type_null_bigint == null)) && (!type_null_bigint.equals(valid.type_null_bigint)))
        return error("type_null_bigint", type_null_bigint, valid.type_null_bigint);
    // col 16
    Long type_not_null_bigint = Long.valueOf(row[++col]);
    if (!type_not_null_bigint.equals(valid.type_not_null_bigint))
        return error("type_not_null_bigint", type_not_null_bigint, valid.type_not_null_bigint);
    // The ExportToFileClient truncates microseconds. Construct a TimestampType here
    // that also truncates microseconds.
    TimestampType type_null_timestamp;
    if (row[++col].equals("NULL")) {
        // col 17
        type_null_timestamp = null;
    } else {
        TimestampType tmp = new TimestampType(row[col]);
        type_null_timestamp = new TimestampType(tmp.asApproximateJavaDate());
    }
    if ((!(type_null_timestamp == null && valid.type_null_timestamp == null)) && (!type_null_timestamp.equals(valid.type_null_timestamp))) {
        System.out.println("CSV value: " + row[col]);
        System.out.println("EXP value: " + valid.type_null_timestamp.toString());
        System.out.println("ACT value: " + type_null_timestamp.toString());
        return error("type_null_timestamp", type_null_timestamp, valid.type_null_timestamp);
    }
    // col 18
    TimestampType type_not_null_timestamp = new TimestampType(row[++col]);
    if (!type_not_null_timestamp.equals(valid.type_not_null_timestamp))
        return error("type_null_timestamp", type_not_null_timestamp, valid.type_not_null_timestamp);
    // col 19
    BigDecimal type_null_decimal = row[++col].equals("NULL") ? null : new BigDecimal(row[col]);
    if ((!(type_null_decimal == null && valid.type_null_decimal == null)) && (!type_null_decimal.equals(valid.type_null_decimal)))
        return error("type_null_decimal", type_null_decimal, valid.type_null_decimal);
    // col 20
    BigDecimal type_not_null_decimal = new BigDecimal(row[++col]);
    if (!type_not_null_decimal.equals(valid.type_not_null_decimal))
        return error("type_not_null_decimal", type_not_null_decimal, valid.type_not_null_decimal);
    // col 21
    Double type_null_float = row[++col].equals("NULL") ? null : Double.valueOf(row[col]);
    if ((!(type_null_float == null && valid.type_null_float == null)) && (!type_null_float.equals(valid.type_null_float))) {
        System.out.println("CSV value: " + row[col]);
        System.out.println("EXP value: " + valid.type_null_float);
        System.out.println("ACT value: " + type_null_float);
        System.out.println("valueOf():" + Double.valueOf("-2155882919525625344.000000000000"));
        System.out.flush();
        return error("type_null_float", type_null_float, valid.type_null_float);
    }
    // col 22
    Double type_not_null_float = Double.valueOf(row[++col]);
    if (!type_not_null_float.equals(valid.type_not_null_float))
        return error("type_not_null_float", type_not_null_float, valid.type_not_null_float);
    // col 23
    String type_null_varchar25 = row[++col].equals("NULL") ? null : row[col];
    if (!(type_null_varchar25 == valid.type_null_varchar25 || type_null_varchar25.equals(valid.type_null_varchar25)))
        return error("type_null_varchar25", type_null_varchar25, valid.type_null_varchar25);
    // col 24
    String type_not_null_varchar25 = row[++col];
    if (!type_not_null_varchar25.equals(valid.type_not_null_varchar25))
        return error("type_not_null_varchar25", type_not_null_varchar25, valid.type_not_null_varchar25);
    // col 25
    String type_null_varchar128 = row[++col].equals("NULL") ? null : row[col];
    if (!(type_null_varchar128 == valid.type_null_varchar128 || type_null_varchar128.equals(valid.type_null_varchar128)))
        return error("type_null_varchar128", type_null_varchar128, valid.type_null_varchar128);
    // col 26
    String type_not_null_varchar128 = row[++col];
    if (!type_not_null_varchar128.equals(valid.type_not_null_varchar128))
        return error("type_not_null_varchar128", type_not_null_varchar128, valid.type_not_null_varchar128);
    // col 27
    String type_null_varchar1024 = row[++col].equals("NULL") ? null : row[col];
    if (!(type_null_varchar1024 == valid.type_null_varchar1024 || type_null_varchar1024.equals(valid.type_null_varchar1024)))
        return error("type_null_varchar1024", type_null_varchar1024, valid.type_null_varchar1024);
    // col 28
    String type_not_null_varchar1024 = row[++col];
    if (!type_not_null_varchar1024.equals(valid.type_not_null_varchar1024))
        return error("type_not_null_varchar1024", type_not_null_varchar1024, valid.type_not_null_varchar1024);
    return null;
}
Also used : Random(java.util.Random) AtomicLong(java.util.concurrent.atomic.AtomicLong) TimestampType(org.voltdb.types.TimestampType) SampleRecord(genqa.procedures.SampleRecord) BigDecimal(java.math.BigDecimal)

Example 9 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class RowCompare method rowcompare.

static int rowcompare(VoltTable t, ResultSet rs) throws SQLException {
    int colMisCount = 0;
    if (rs.next()) {
        // we already checked key and value via SELECT; now work through the rest of the types
        // not_null rows are simple compares. nullable types need to check for null as well
        byte ntiVal = (byte) t.get("TYPE_NULL_TINYINT", VoltType.TINYINT);
        // System.out.println("Volt TYPE_NULL_TINYINT: " + ntiVal);
        byte type_null_tinyint = rs.getByte("TYPE_NULL_TINYINT");
        if (rs.wasNull()) {
            type_null_tinyint = org.voltdb.VoltType.NULL_TINYINT;
        }
        // System.out.println("JDBC TYPE_NULL_TINYINT: " + type_null_tinyint);
        if (ntiVal != type_null_tinyint) {
            colMisCount += reportMismatch("type_null_tinyint", String.valueOf(type_null_tinyint), String.valueOf(ntiVal));
        }
        byte tiVal = (byte) t.get("TYPE_NOT_NULL_TINYINT", VoltType.TINYINT);
        byte type_not_null_tinyint = rs.getByte("TYPE_NOT_NULL_TINYINT");
        if (tiVal != type_not_null_tinyint) {
            colMisCount += reportMismatch("type_not_null_tinyint", String.valueOf(type_not_null_tinyint), String.valueOf(tiVal));
        }
        short nsiVal = (short) t.get("TYPE_NULL_SMALLINT", VoltType.SMALLINT);
        short type_null_smallint = rs.getShort("TYPE_NULL_SMALLINT");
        if (rs.wasNull()) {
            type_null_smallint = org.voltdb.VoltType.NULL_SMALLINT;
        }
        if (nsiVal != type_null_smallint) {
            colMisCount += reportMismatch("type_null_smallint", String.valueOf(type_null_smallint), String.valueOf(nsiVal));
        }
        short siVal = (short) t.get("TYPE_NOT_NULL_SMALLINT", VoltType.SMALLINT);
        short type_not_null_smallint = rs.getShort("TYPE_NOT_NULL_SMALLINT");
        if (siVal != type_not_null_smallint) {
            colMisCount += reportMismatch("type_not_null_smallint", String.valueOf(type_not_null_smallint), String.valueOf(siVal));
        }
        int nintVal = (int) t.get("TYPE_NULL_INTEGER", VoltType.INTEGER);
        int type_null_integer = rs.getInt("TYPE_NULL_INTEGER");
        if (rs.wasNull()) {
            type_null_integer = org.voltdb.VoltType.NULL_INTEGER;
        }
        if (nintVal != type_null_integer) {
            colMisCount += reportMismatch("type_null_integer", String.valueOf(type_null_integer), String.valueOf(nintVal));
        }
        int intVal = (int) t.get("TYPE_NOT_NULL_INTEGER", VoltType.INTEGER);
        int type_not_null_integer = rs.getInt("TYPE_NOT_NULL_INTEGER");
        if (intVal != type_not_null_integer) {
            colMisCount += reportMismatch("type_not_null_integer", String.valueOf(type_not_null_integer), String.valueOf(intVal));
        }
        long nbigVal = (long) t.get("TYPE_NULL_BIGINT", VoltType.BIGINT);
        long type_null_bigint = rs.getLong("TYPE_NULL_BIGINT");
        if (rs.wasNull()) {
            type_null_bigint = org.voltdb.VoltType.NULL_BIGINT;
        }
        if (nbigVal != type_null_bigint) {
            colMisCount += reportMismatch("type_null_bigint", String.valueOf(type_null_bigint), String.valueOf(nbigVal));
        }
        long bigVal = (long) t.get("TYPE_NOT_NULL_BIGINT", VoltType.BIGINT);
        long type_not_null_bigint = rs.getLong("TYPE_NOT_NULL_BIGINT");
        if (bigVal != type_not_null_bigint) {
            colMisCount += reportMismatch("type_not_null_bigint", String.valueOf(type_not_null_bigint), String.valueOf(bigVal));
        }
        // a direct string comparision of volt TimeStampType.toString()
        // and jdbc String type via ResultSet.getString()
        // isn't consistent, convert it to JDBC Timestamps and then compare.
        // ex: volt syntax: 1970-01-10 13:56:40.549-05
        // postgres syntax: 1970-01-10 13:56:40.549000
        TimestampType ntsVal = (TimestampType) t.get("TYPE_NULL_TIMESTAMP", VoltType.TIMESTAMP);
        if (ntsVal != null) {
            // compare it as string values
            Timestamp voltTS = ntsVal.asJavaTimestamp();
            Timestamp jdbcTS = rs.getTimestamp("TYPE_NULL_TIMESTAMP");
            if (!voltTS.toString().equals(jdbcTS.toString())) {
                colMisCount += reportMismatch("type_null_timestamp strings", jdbcTS.toString(), voltTS.toString());
            }
            // compare it as microsecond time values
            if (jdbcTS.getTime() * 1000 != ntsVal.getTime()) {
                colMisCount += reportMismatch("type_null_timestamp microseconds", String.valueOf(jdbcTS.getTime() * 1000), String.valueOf(ntsVal.getTime()));
            }
        } else {
            // if volt is null, jdbc should be null also
            Timestamp jdbcTS = rs.getTimestamp("TYPE_NULL_TIMESTAMP");
            if (rs.getTimestamp("TYPE_NULL_TIMESTAMP") != null) {
                colMisCount += reportMismatch("type_null_timestamp is null", String.valueOf(jdbcTS), String.valueOf(ntsVal));
            }
        }
        double nfloatVal = (double) t.get("TYPE_NULL_FLOAT", VoltType.FLOAT);
        double type_null_float = (double) rs.getFloat("TYPE_NULL_FLOAT");
        if (rs.wasNull()) {
            type_null_float = org.voltdb.VoltType.NULL_FLOAT;
        }
        if (Math.abs(nfloatVal - type_null_float) > 0.0001) {
            colMisCount += reportMismatch("type_null_float", String.valueOf(type_null_float), String.valueOf(nfloatVal));
        }
        double floatVal = (double) t.get("TYPE_NOT_NULL_FLOAT", VoltType.FLOAT);
        double type_not_null_float = (double) rs.getFloat("TYPE_NOT_NULL_FLOAT");
        if (Math.abs(floatVal - type_not_null_float) > 0.0001) {
            colMisCount += reportMismatch("type_not_null_float", String.valueOf(type_not_null_float), String.valueOf(floatVal));
        }
        BigDecimal ndecimalVal = (BigDecimal) t.get("TYPE_NULL_DECIMAL", VoltType.DECIMAL);
        BigDecimal type_null_decimal = rs.getBigDecimal("TYPE_NULL_DECIMAL");
        if (!(ndecimalVal == null && rs.wasNull()) && !ndecimalVal.equals(type_null_decimal)) {
            colMisCount += reportMismatch("type_null_decimal", type_null_decimal.toString(), ndecimalVal.toString());
        }
        BigDecimal decimalVal = (BigDecimal) t.get("TYPE_NOT_NULL_DECIMAL", VoltType.DECIMAL);
        BigDecimal type_not_null_decimal = rs.getBigDecimal("TYPE_NOT_NULL_DECIMAL");
        if (!decimalVal.equals(type_not_null_decimal)) {
            colMisCount += reportMismatch("type_not_null_decimal", type_not_null_decimal.toString(), decimalVal.toString());
        }
        String nstring25Val = (String) t.get("TYPE_NULL_VARCHAR25", VoltType.STRING);
        String type_null_varchar25 = rs.getString("TYPE_NULL_VARCHAR25");
        if (!(nstring25Val == null && rs.wasNull()) && !nstring25Val.equals(type_null_varchar25)) {
            colMisCount += reportMismatch("type_null_varchar25", type_null_varchar25, nstring25Val);
        }
        String string25Val = (String) t.get("TYPE_NOT_NULL_VARCHAR25", VoltType.STRING);
        String type_not_null_varchar25 = rs.getString("TYPE_NOT_NULL_VARCHAR25");
        if (!string25Val.equals(type_not_null_varchar25)) {
            colMisCount += reportMismatch("type_not_null_varchar25", type_not_null_varchar25, string25Val);
        }
        String nstring128Val = (String) t.get("TYPE_NULL_VARCHAR128", VoltType.STRING);
        String type_null_varchar128 = rs.getString("TYPE_NULL_VARCHAR128");
        if (!(nstring128Val == null && rs.wasNull()) && !nstring128Val.equals(type_null_varchar128)) {
            colMisCount += reportMismatch("type_null_varchar128", type_null_varchar128, nstring128Val);
        }
        String string128Val = (String) t.get("TYPE_NOT_NULL_VARCHAR128", VoltType.STRING);
        String type_not_null_varchar128 = rs.getString("TYPE_NOT_NULL_VARCHAR128");
        if (!string128Val.equals(type_not_null_varchar128)) {
            colMisCount += reportMismatch("type_not_null_varchar128", type_not_null_varchar128, string128Val);
        }
        String nstring1024Val = (String) t.get("TYPE_NULL_VARCHAR1024", VoltType.STRING);
        String type_null_varchar1024 = rs.getString("TYPE_NULL_VARCHAR1024");
        if (!(nstring1024Val == null && rs.wasNull()) && !nstring1024Val.equals(type_null_varchar1024)) {
            colMisCount += reportMismatch("type_null_varchar1024", type_null_varchar1024, nstring1024Val);
        }
        String string1024Val = (String) t.get("TYPE_NOT_NULL_VARCHAR1024", VoltType.STRING);
        String type_not_null_varchar1024 = rs.getString("TYPE_NOT_NULL_VARCHAR1024");
        if (!string1024Val.equals(type_not_null_varchar1024)) {
            colMisCount += reportMismatch("type_not_null_varchar1024", type_not_null_varchar1024, string1024Val);
        }
    } else {
        System.out.println("In rowRowCompare:compare: no JDBC row available");
    }
    // handle the colMisCount in the calling function
    return colMisCount;
}
Also used : TimestampType(org.voltdb.types.TimestampType) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Example 10 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class InsertImport2 method run.

public long run(long key, long value, byte rowid_group, byte type_null_tinyint, byte type_not_null_tinyint, short type_null_smallint, short type_not_null_smallint, int type_null_integer, int type_not_null_integer, long type_null_bigint, long type_not_null_bigint, TimestampType type_null_timestamp, TimestampType type_not_null_timestamp, double type_null_float, double type_not_null_float, BigDecimal type_null_decimal, BigDecimal type_not_null_decimal, String type_null_varchar25, String type_not_null_varchar25, String type_null_varchar128, String type_not_null_varchar128, String type_null_varchar1024, String type_not_null_varchar1024) {
    // column positions, used in "get" calls below
    final int TYPE_NULL_TINYINT = 3;
    final int TYPE_NOT_NULL_TINYINT = 4;
    final int TYPE_NULL_SMALLINT = 5;
    final int TYPE_NOT_NULL_SMALLINT = 6;
    final int TYPE_NULL_INTEGER = 7;
    final int TYPE_NOT_NULL_INTEGER = 8;
    final int TYPE_NULL_BIGINT = 9;
    final int TYPE_NOT_NULL_BIGINT = 10;
    final int TYPE_NULL_TIMESTAMP = 11;
    final int TYPE_NOT_NULL_TIMESTAMP = 12;
    final int TYPE_NULL_FLOAT = 13;
    final int TYPE_NOT_NULL_FLOAT = 14;
    final int TYPE_NULL_DECIMAL = 15;
    final int TYPE_NOT_NULL_DECIMAL = 16;
    final int TYPE_NULL_VARCHAR25 = 17;
    final int TYPE_NOT_NULL_VARCHAR25 = 18;
    final int TYPE_NULL_VARCHAR128 = 19;
    final int TYPE_NOT_NULL_VARCHAR128 = 20;
    final int TYPE_NULL_VARCHAR1024 = 21;
    final int TYPE_NOT_NULL_VARCHAR1024 = 22;
    // find mirror row that matches import
    voltQueueSQL(selectMirrorRow, key, value);
    VoltTable[] mirrorResults = voltExecuteSQL();
    VoltTable rowData = mirrorResults[0];
    long deletedCount = 0;
    boolean rowCheckOk = true;
    if (rowData.getRowCount() == 1) {
        // we already checked key and value via SELECT; now work through the rest of the types
        // not_null rows are simple compares. nullable types need to check for null as well
        byte ntiVal = (byte) rowData.fetchRow(0).get(TYPE_NULL_TINYINT, VoltType.TINYINT);
        if (ntiVal != type_null_tinyint) {
            rowCheckOk = reportMismatch("type_null_tinyint", String.valueOf(type_null_tinyint), String.valueOf(ntiVal));
        }
        byte tiVal = (byte) rowData.fetchRow(0).get(TYPE_NOT_NULL_TINYINT, VoltType.TINYINT);
        if (tiVal != type_not_null_tinyint) {
            rowCheckOk = reportMismatch("type_not_null_tinyint", String.valueOf(type_not_null_tinyint), String.valueOf(tiVal));
        }
        short nsiVal = (short) rowData.fetchRow(0).get(TYPE_NULL_SMALLINT, VoltType.SMALLINT);
        if (nsiVal != type_null_smallint) {
            rowCheckOk = reportMismatch("type_null_smallint", String.valueOf(type_null_smallint), String.valueOf(nsiVal));
        }
        short siVal = (short) rowData.fetchRow(0).get(TYPE_NOT_NULL_SMALLINT, VoltType.SMALLINT);
        if (siVal != type_not_null_smallint) {
            rowCheckOk = reportMismatch("type_not_null_smallint", String.valueOf(type_not_null_smallint), String.valueOf(siVal));
        }
        int nintVal = (int) rowData.fetchRow(0).get(TYPE_NULL_INTEGER, VoltType.INTEGER);
        if (nintVal != type_null_integer) {
            rowCheckOk = reportMismatch("type_null_integer", String.valueOf(type_null_integer), String.valueOf(nintVal));
        }
        int intVal = (int) rowData.fetchRow(0).get(TYPE_NOT_NULL_INTEGER, VoltType.INTEGER);
        if (intVal != type_not_null_integer) {
            rowCheckOk = reportMismatch("type_not_null_integer", String.valueOf(type_not_null_integer), String.valueOf(intVal));
        }
        long nbigVal = (long) rowData.fetchRow(0).get(TYPE_NULL_BIGINT, VoltType.BIGINT);
        if (nbigVal != type_null_bigint) {
            rowCheckOk = reportMismatch("type_null_bigint", String.valueOf(type_null_bigint), String.valueOf(nbigVal));
        }
        long bigVal = (long) rowData.fetchRow(0).get(TYPE_NOT_NULL_BIGINT, VoltType.BIGINT);
        if (bigVal != type_not_null_bigint) {
            rowCheckOk = reportMismatch("type_not_null_bigint", String.valueOf(type_not_null_bigint), String.valueOf(bigVal));
        }
        TimestampType ntsVal = (TimestampType) rowData.fetchRow(0).get(TYPE_NULL_TIMESTAMP, VoltType.TIMESTAMP);
        if (!(ntsVal == null && type_null_timestamp == null) && !ntsVal.equals(type_null_timestamp)) {
            rowCheckOk = reportMismatch("type_null_timestamp", type_null_timestamp.toString(), ntsVal.toString());
        }
        TimestampType tsVal = (TimestampType) rowData.fetchRow(0).get(TYPE_NOT_NULL_TIMESTAMP, VoltType.TIMESTAMP);
        if (!tsVal.equals(type_not_null_timestamp)) {
            rowCheckOk = reportMismatch("type_not_null_timestamp", type_not_null_timestamp.toString(), tsVal.toString());
        }
        double nfloatVal = (double) rowData.fetchRow(0).get(TYPE_NULL_FLOAT, VoltType.FLOAT);
        if (nfloatVal != type_null_float) {
            rowCheckOk = reportMismatch("type_null_float", String.valueOf(type_null_float), String.valueOf(nfloatVal));
        }
        double floatVal = (double) rowData.fetchRow(0).get(TYPE_NOT_NULL_FLOAT, VoltType.FLOAT);
        if (floatVal != type_not_null_float) {
            rowCheckOk = reportMismatch("type_not_null_float", String.valueOf(type_not_null_float), String.valueOf(floatVal));
        }
        BigDecimal ndecimalVal = (BigDecimal) rowData.fetchRow(0).get(TYPE_NULL_DECIMAL, VoltType.DECIMAL);
        if (!(ndecimalVal == null && type_null_decimal == null) && !ndecimalVal.equals(type_null_decimal)) {
            rowCheckOk = reportMismatch("type_null_decimal", type_null_decimal.toString(), ndecimalVal.toString());
        }
        BigDecimal decimalVal = (BigDecimal) rowData.fetchRow(0).get(TYPE_NOT_NULL_DECIMAL, VoltType.DECIMAL);
        if (!decimalVal.equals(type_not_null_decimal)) {
            rowCheckOk = reportMismatch("type_not_null_decimal", type_not_null_decimal.toString(), decimalVal.toString());
        }
        String nstring25Val = (String) rowData.fetchRow(0).get(TYPE_NULL_VARCHAR25, VoltType.STRING);
        if (!(nstring25Val == null && type_null_varchar25 == null) && !nstring25Val.equals(type_null_varchar25)) {
            rowCheckOk = reportMismatch("type_null_varchar25", type_null_varchar25, nstring25Val);
        }
        String string25Val = (String) rowData.fetchRow(0).get(TYPE_NOT_NULL_VARCHAR25, VoltType.STRING);
        if (!string25Val.equals(type_not_null_varchar25)) {
            rowCheckOk = reportMismatch("type_not_null_varchar25", type_not_null_varchar25, string25Val);
        }
        String nstring128Val = (String) rowData.fetchRow(0).get(TYPE_NULL_VARCHAR128, VoltType.STRING);
        if (!(nstring128Val == null && type_null_varchar128 == null) && !nstring128Val.equals(type_null_varchar128)) {
            rowCheckOk = reportMismatch("type_null_varchar128", type_null_varchar128, nstring128Val);
        }
        String string128Val = (String) rowData.fetchRow(0).get(TYPE_NOT_NULL_VARCHAR128, VoltType.STRING);
        if (!string128Val.equals(type_not_null_varchar128)) {
            rowCheckOk = reportMismatch("type_not_null_varchar128", type_not_null_varchar128, string128Val);
        }
        String nstring1024Val = (String) rowData.fetchRow(0).get(TYPE_NULL_VARCHAR1024, VoltType.STRING);
        if (!(nstring1024Val == null && type_null_varchar1024 == null) && !nstring1024Val.equals(type_null_varchar1024)) {
            rowCheckOk = reportMismatch("type_null_varchar1024", type_null_varchar1024, nstring1024Val);
        }
        String string1024Val = (String) rowData.fetchRow(0).get(TYPE_NOT_NULL_VARCHAR1024, VoltType.STRING);
        if (!string1024Val.equals(type_not_null_varchar1024)) {
            rowCheckOk = reportMismatch("type_not_null_varchar1024", type_not_null_varchar1024, string1024Val);
        }
        if (rowCheckOk) {
            // delete the row
            voltQueueSQL(deleteMirrorRow, EXPECT_SCALAR_LONG, key, value);
            deletedCount = voltExecuteSQL()[0].asScalarLong();
        } else {
            // there was a data mismatch; set VALUE_MISMATCH, which will be noticed by client
            voltQueueSQL(updateMismatch, key, value, 1);
            voltExecuteSQL();
            return 0;
        }
        if (deletedCount != 1) {
            System.out.println("Rows deleted: " + deletedCount + ", key: " + key + ", value: " + value);
        }
    } else {
        // add to import table as indicator of dupe or mismatch
        voltQueueSQL(importInsert, key, value, rowid_group, type_null_tinyint, type_not_null_tinyint, type_null_smallint, type_not_null_smallint, type_null_integer, type_not_null_integer, type_null_bigint, type_not_null_bigint, type_null_timestamp, type_not_null_timestamp, type_null_float, type_not_null_float, type_null_decimal, type_not_null_decimal, type_null_varchar25, type_not_null_varchar25, type_null_varchar128, type_not_null_varchar128, type_null_varchar1024, type_not_null_varchar1024);
        voltExecuteSQL();
    }
    // update the counts tables so we can track progress and results
    // since the SP can't return results to the client
    voltQueueSQL(selectCounts);
    VoltTable[] result = voltExecuteSQL();
    VoltTable data = result[0];
    long nrows = data.getRowCount();
    if (nrows > 0) {
        long ck = data.fetchRow(0).getLong(0);
        voltQueueSQL(updateCounts, deletedCount, ck);
        voltExecuteSQL(true);
    } else {
        voltQueueSQL(insertCounts, key, deletedCount);
        voltExecuteSQL(true);
    }
    return 0;
}
Also used : TimestampType(org.voltdb.types.TimestampType) VoltTable(org.voltdb.VoltTable) BigDecimal(java.math.BigDecimal)

Aggregations

TimestampType (org.voltdb.types.TimestampType)127 VoltTable (org.voltdb.VoltTable)37 BigDecimal (java.math.BigDecimal)30 Test (org.junit.Test)23 Client (org.voltdb.client.Client)19 ArrayList (java.util.ArrayList)16 IOException (java.io.IOException)11 GeographyValue (org.voltdb.types.GeographyValue)11 GeographyPointValue (org.voltdb.types.GeographyPointValue)10 Date (java.util.Date)9 File (java.io.File)7 VoltTableRow (org.voltdb.VoltTableRow)7 ProcCallException (org.voltdb.client.ProcCallException)7 ByteBuffer (java.nio.ByteBuffer)5 SimpleDateFormat (java.text.SimpleDateFormat)5 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)5 ClientResponse (org.voltdb.client.ClientResponse)5 Random (java.util.Random)4 VoltType (org.voltdb.VoltType)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2