Search in sources :

Example 1 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue 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 2 with GeographyPointValue

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

the class VoltTableRow method putJSONRep.

/**
     *
     * @param columnIndex
     * @param js
     * @throws JSONException
     */
void putJSONRep(int columnIndex, JSONStringer js) throws JSONException {
    long value;
    double dvalue;
    VoltType columnType = getColumnType(columnIndex);
    switch(columnType) {
        case TINYINT:
            value = getLong(columnIndex);
            if (wasNull()) {
                js.valueNull();
            } else {
                js.value(value);
            }
            break;
        case SMALLINT:
            value = getLong(columnIndex);
            if (wasNull()) {
                js.valueNull();
            } else {
                js.value(value);
            }
            break;
        case INTEGER:
            value = getLong(columnIndex);
            if (wasNull()) {
                js.valueNull();
            } else {
                js.value(value);
            }
            break;
        case BIGINT:
            value = getLong(columnIndex);
            if (wasNull()) {
                js.valueNull();
            } else {
                js.value(value);
            }
            break;
        case TIMESTAMP:
            value = getTimestampAsLong(columnIndex);
            if (wasNull()) {
                js.valueNull();
            } else {
                js.value(value);
            }
            break;
        case FLOAT:
            dvalue = getDouble(columnIndex);
            if (wasNull()) {
                js.valueNull();
            } else if (Double.isNaN(dvalue)) {
                js.value(Double.toString(dvalue));
            } else if (Double.isInfinite(dvalue)) {
                js.value(Double.toString(dvalue));
            } else {
                js.value(dvalue);
            }
            break;
        case STRING:
            js.value(getString(columnIndex));
            break;
        case VARBINARY:
            byte[] bin = getVarbinary(columnIndex);
            js.value(Encoder.hexEncode(bin));
            break;
        case DECIMAL:
            Object dec = getDecimalAsBigDecimal(columnIndex);
            if (wasNull()) {
                js.valueNull();
            } else {
                js.value(dec.toString());
            }
            break;
        case GEOGRAPHY_POINT:
            GeographyPointValue pt = getGeographyPointValue(columnIndex);
            if (wasNull()) {
                js.valueNull();
            } else {
                js.value(pt.toString());
            }
            break;
        case GEOGRAPHY:
            GeographyValue gv = getGeographyValue(columnIndex);
            if (wasNull()) {
                js.valueNull();
            } else {
                js.value(gv.toString());
            }
            break;
        // VoltType includes a few values that aren't valid column value types
        case INVALID:
            break;
        case NULL:
            break;
        case NUMERIC:
            break;
        case BOOLEAN:
            break;
        case VOLTTABLE:
            break;
    }
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 3 with GeographyPointValue

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

the class SampleGeoRecord method nextGeography.

// POLYGON ( ( 1.5 3.0, 0.0 0.0, 3.0 0.0, 1.5 3.0 ) )
private static Object nextGeography(Random rand, boolean isNullable, int minLength, int maxLength) {
    if (isNullable && rand.nextBoolean())
        return null;
    // we need to have at least 4 vertices
    int numVertices = rand.nextInt(6) + 4;
    double sizeOfHole = rand.nextDouble();
    GeographyPointValue center = GeographyPointValue.fromWKT("POINT(0 0)");
    GeographyPointValue firstVertex = GeographyPointValue.fromWKT("POINT(1 1)");
    GeographyValue poly = PolygonFactory.CreateRegularConvex(center, firstVertex, numVertices, sizeOfHole);
    return poly;
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 4 with GeographyPointValue

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

the class ProcToTestTypeConversion method getInListParameter.

private Object getInListParameter(byte valueTypeToPopulateWith, boolean strTs) {
    VoltType toType = VoltType.get(valueTypeToPopulateWith);
    switch(toType) {
        case TINYINT:
            byte[] tinyValue = { m_byteVal, m_byteVal };
            return tinyValue;
        case SMALLINT:
            short[] shortValue = { m_shortVal, m_shortVal };
            return shortValue;
        case INTEGER:
            int[] intValue = { m_intVal, m_intVal };
            return intValue;
        case BIGINT:
            long[] bigintValue = { m_bigIntVal, m_bigIntVal };
            return bigintValue;
        case FLOAT:
            double[] floatValue = { m_floatVal, m_floatVal };
            return floatValue;
        case DECIMAL:
            BigDecimal[] bigdecValue = { m_bigDecVal, m_bigDecVal };
            return bigdecValue;
        case TIMESTAMP:
            TimestampType[] tsValue = { m_tsVal, m_tsVal };
            return tsValue;
        case STRING:
            String str = strTs ? m_strTs : m_strNum;
            String[] strValue = { str, str };
            return strValue;
        case VARBINARY:
            byte[][] binValue = { { m_byteVal, m_byteVal }, { m_byteVal, m_byteVal } };
            return binValue;
        case GEOGRAPHY_POINT:
            GeographyPointValue[] ptValue = { m_pt, m_pt };
            return ptValue;
        case GEOGRAPHY:
            GeographyValue[] polyValue = { m_poly, m_poly };
            return polyValue;
        default:
            assert (false);
            break;
    }
    return null;
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) BigDecimal(java.math.BigDecimal) VoltType(org.voltdb.VoltType) TimestampType(org.voltdb.types.TimestampType) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 5 with GeographyPointValue

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

the class TestParameterConverter method testOneStringToPoint.

public void testOneStringToPoint(String rep, GeographyPointValue pt, double epsilon) throws Exception {
    Object r = ParameterConverter.tryToMakeCompatible(GeographyPointValue.class, rep);
    assertTrue("expected GeographyPointValue", r.getClass() == GeographyPointValue.class);
    GeographyPointValue rpt = (GeographyPointValue) r;
    assertEquals("Cannot convert string to geography point.", pt.getLatitude(), rpt.getLatitude(), epsilon);
    assertEquals("Cannot convert string to geography point.", pt.getLongitude(), rpt.getLongitude(), epsilon);
}
Also used : GeographyPointValue(org.voltdb.types.GeographyPointValue)

Aggregations

GeographyPointValue (org.voltdb.types.GeographyPointValue)38 GeographyValue (org.voltdb.types.GeographyValue)23 VoltTable (org.voltdb.VoltTable)11 BigDecimal (java.math.BigDecimal)10 TimestampType (org.voltdb.types.TimestampType)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Client (org.voltdb.client.Client)7 IOException (java.io.IOException)5 JSONString (org.json_voltpatches.JSONString)3 VoltType (org.voltdb.VoltType)3 ByteBuffer (java.nio.ByteBuffer)2 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)2 NullCallback (org.voltdb.client.NullCallback)2 File (java.io.File)1 BigInteger (java.math.BigInteger)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 SimpleDateFormat (java.text.SimpleDateFormat)1