Search in sources :

Example 11 with ColumnSchema

use of com.nearinfinity.honeycomb.mysql.schema.ColumnSchema in project honeycomb by altamiracorp.

the class FieldParserTest method testParseULong.

@Test
public void testParseULong() throws ParseException {
    ColumnSchema schema = ColumnSchema.builder(COLUMN_NAME, ColumnType.ULONG).build();
    assertEquals(ByteBuffer.wrap(Longs.toByteArray(0x00L)), FieldParser.parse("0", schema));
    assertEquals(ByteBuffer.wrap(Longs.toByteArray(0x7BL)), FieldParser.parse("123", schema));
    assertEquals(ByteBuffer.wrap(Longs.toByteArray(0xFFFFFFFFFFFFFFFFL)), FieldParser.parse("18446744073709551615", schema));
}
Also used : ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) Test(org.junit.Test)

Example 12 with ColumnSchema

use of com.nearinfinity.honeycomb.mysql.schema.ColumnSchema in project honeycomb by altamiracorp.

the class FieldParserTest method testParseDateTime.

@Test
public void testParseDateTime() throws Exception {
    ColumnSchema schema = ColumnSchema.builder(COLUMN_NAME, ColumnType.DATETIME).build();
    final String expectedParsedDateTime = "1989-05-13 07:32:15";
    final List<String> formats = ImmutableList.of(expectedParsedDateTime, "1989.05.13 07:32:15", "1989/05/13 07:32:15", "19890513 073215");
    for (final String format : formats) {
        assertEquals(ByteBuffer.wrap(expectedParsedDateTime.getBytes()), FieldParser.parse(format, schema));
    }
}
Also used : ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) Test(org.junit.Test)

Example 13 with ColumnSchema

use of com.nearinfinity.honeycomb.mysql.schema.ColumnSchema in project honeycomb by altamiracorp.

the class FieldParserTest method testParseEmptyValueNonNullableSchemaLongType.

/**
     * Tests a parse request with an empty value and a non-nullable
     * {@link ColumnSchema} with a {@link ColumnType} not equal to
     * {@link ColumnType#STRING} or {@link ColumnType#BINARY}
     *
     * @throws ParseException
     */
@Test(expected = IllegalArgumentException.class)
public void testParseEmptyValueNonNullableSchemaLongType() throws ParseException {
    ColumnSchema schema = ColumnSchema.builder(COLUMN_NAME, ColumnType.LONG).setIsNullable(false).build();
    assertNull(FieldParser.parse(EMPTY_STRING, schema));
}
Also used : ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) Test(org.junit.Test)

Example 14 with ColumnSchema

use of com.nearinfinity.honeycomb.mysql.schema.ColumnSchema in project honeycomb by altamiracorp.

the class FieldParserTest method testParseDoubleZeroValue.

@Test
public void testParseDoubleZeroValue() throws ParseException {
    ColumnSchema schema = ColumnSchema.builder(COLUMN_NAME, ColumnType.DOUBLE).build();
    // Note: These values are all big endian, as per the JVM
    assertEquals(ByteBuffer.wrap(Bytes.toBytes(0x00L)), FieldParser.parse("0.0", schema));
    assertEquals(ByteBuffer.wrap(Longs.toByteArray(0x40283D70A3D70A3DL)), FieldParser.parse("12.12", schema));
    assertEquals(ByteBuffer.wrap(Longs.toByteArray(0xC0283D70A3D70A3DL)), FieldParser.parse("-12.12", schema));
}
Also used : ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) Test(org.junit.Test)

Example 15 with ColumnSchema

use of com.nearinfinity.honeycomb.mysql.schema.ColumnSchema in project honeycomb by altamiracorp.

the class FieldParserTest method testParseTime.

@Test
public void testParseTime() throws Exception {
    ColumnSchema schema = ColumnSchema.builder(COLUMN_NAME, ColumnType.TIME).build();
    final String expectedParsedTime = "07:32:15";
    final List<String> formats = ImmutableList.of(expectedParsedTime, "073215");
    for (final String format : formats) {
        assertEquals(ByteBuffer.wrap(expectedParsedTime.getBytes()), FieldParser.parse(format, schema));
    }
}
Also used : ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) Test(org.junit.Test)

Aggregations

ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)28 Test (org.junit.Test)22 TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)9 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)5 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 RowKey (com.nearinfinity.honeycomb.hbase.rowkey.RowKey)1 HandlerProxy (com.nearinfinity.honeycomb.mysql.HandlerProxy)1 Row (com.nearinfinity.honeycomb.mysql.Row)1 ColumnType (com.nearinfinity.honeycomb.mysql.gen.ColumnType)1 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1 Bytes (org.apache.hadoop.hbase.util.Bytes)1