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();
}
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;
}
}
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;
}
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;
}
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);
}
Aggregations