Search in sources :

Example 6 with Parser

use of com.google.cloud.spanner.pgadapter.parsers.Parser in project pgadapter by GoogleCloudPlatform.

the class ParserTest method testBinaryParsing.

@Test
public void testBinaryParsing() {
    ByteArray value = ByteArray.copyFrom(new byte[] { (byte) 0b01010101, (byte) 0b10101010 });
    byte[] byteResult = { (byte) 0b01010101, (byte) 0b10101010 };
    byte[] stringResult = { 'U', '\\', '2', '5', '2' };
    Parser parsedValue = new BinaryParser(value);
    validate(parsedValue, byteResult, stringResult, byteResult);
    validateCreateBinary(byteResult, Oid.BYTEA, value);
    validateCreateText(stringResult, Oid.BYTEA, value);
}
Also used : ByteArray(com.google.cloud.ByteArray) BinaryParser(com.google.cloud.spanner.pgadapter.parsers.BinaryParser) DoubleParser(com.google.cloud.spanner.pgadapter.parsers.DoubleParser) StatementParser(com.google.cloud.spanner.pgadapter.utils.StatementParser) ArrayParser(com.google.cloud.spanner.pgadapter.parsers.ArrayParser) BooleanParser(com.google.cloud.spanner.pgadapter.parsers.BooleanParser) NumericParser(com.google.cloud.spanner.pgadapter.parsers.NumericParser) StringParser(com.google.cloud.spanner.pgadapter.parsers.StringParser) BinaryParser(com.google.cloud.spanner.pgadapter.parsers.BinaryParser) Parser(com.google.cloud.spanner.pgadapter.parsers.Parser) IntegerParser(com.google.cloud.spanner.pgadapter.parsers.IntegerParser) CopyTreeParser(com.google.cloud.spanner.pgadapter.parsers.copy.CopyTreeParser) LongParser(com.google.cloud.spanner.pgadapter.parsers.LongParser) DateParser(com.google.cloud.spanner.pgadapter.parsers.DateParser) TimestampParser(com.google.cloud.spanner.pgadapter.parsers.TimestampParser) Test(org.junit.Test)

Example 7 with Parser

use of com.google.cloud.spanner.pgadapter.parsers.Parser in project pgadapter by GoogleCloudPlatform.

the class ParserTest method testStringParsing.

@Test
public void testStringParsing() {
    String value = "This is a String.";
    byte[] stringResult = { 'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 'S', 't', 'r', 'i', 'n', 'g', '.' };
    Parser parsedValue = new StringParser(value);
    validate(parsedValue, stringResult, stringResult, stringResult);
    validateCreateBinary(stringResult, Oid.VARCHAR, value);
    validateCreateText(stringResult, Oid.VARCHAR, value);
}
Also used : StringParser(com.google.cloud.spanner.pgadapter.parsers.StringParser) DoubleParser(com.google.cloud.spanner.pgadapter.parsers.DoubleParser) StatementParser(com.google.cloud.spanner.pgadapter.utils.StatementParser) ArrayParser(com.google.cloud.spanner.pgadapter.parsers.ArrayParser) BooleanParser(com.google.cloud.spanner.pgadapter.parsers.BooleanParser) NumericParser(com.google.cloud.spanner.pgadapter.parsers.NumericParser) StringParser(com.google.cloud.spanner.pgadapter.parsers.StringParser) BinaryParser(com.google.cloud.spanner.pgadapter.parsers.BinaryParser) Parser(com.google.cloud.spanner.pgadapter.parsers.Parser) IntegerParser(com.google.cloud.spanner.pgadapter.parsers.IntegerParser) CopyTreeParser(com.google.cloud.spanner.pgadapter.parsers.copy.CopyTreeParser) LongParser(com.google.cloud.spanner.pgadapter.parsers.LongParser) DateParser(com.google.cloud.spanner.pgadapter.parsers.DateParser) TimestampParser(com.google.cloud.spanner.pgadapter.parsers.TimestampParser) Test(org.junit.Test)

Example 8 with Parser

use of com.google.cloud.spanner.pgadapter.parsers.Parser in project pgadapter by GoogleCloudPlatform.

the class ParserTest method testNegativeLongParsing.

@Test
public void testNegativeLongParsing() {
    long value = -1234567890L;
    byte[] byteResult = { -1, -1, -1, -1, -74, 105, -3, 46 };
    byte[] stringResult = { '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
    Parser parsedValue = new LongParser(value);
    validate(parsedValue, byteResult, stringResult, stringResult);
    validateCreateBinary(byteResult, Oid.INT8, value);
    validateCreateText(stringResult, Oid.INT8, value);
}
Also used : LongParser(com.google.cloud.spanner.pgadapter.parsers.LongParser) DoubleParser(com.google.cloud.spanner.pgadapter.parsers.DoubleParser) StatementParser(com.google.cloud.spanner.pgadapter.utils.StatementParser) ArrayParser(com.google.cloud.spanner.pgadapter.parsers.ArrayParser) BooleanParser(com.google.cloud.spanner.pgadapter.parsers.BooleanParser) NumericParser(com.google.cloud.spanner.pgadapter.parsers.NumericParser) StringParser(com.google.cloud.spanner.pgadapter.parsers.StringParser) BinaryParser(com.google.cloud.spanner.pgadapter.parsers.BinaryParser) Parser(com.google.cloud.spanner.pgadapter.parsers.Parser) IntegerParser(com.google.cloud.spanner.pgadapter.parsers.IntegerParser) CopyTreeParser(com.google.cloud.spanner.pgadapter.parsers.copy.CopyTreeParser) LongParser(com.google.cloud.spanner.pgadapter.parsers.LongParser) DateParser(com.google.cloud.spanner.pgadapter.parsers.DateParser) TimestampParser(com.google.cloud.spanner.pgadapter.parsers.TimestampParser) Test(org.junit.Test)

Example 9 with Parser

use of com.google.cloud.spanner.pgadapter.parsers.Parser in project pgadapter by GoogleCloudPlatform.

the class ParserTest method testNegativeDoubleParsing.

@Test
public void testNegativeDoubleParsing() {
    double value = -1234.56789d;
    byte[] byteResult = { -64, -109, 74, 69, -124, -12, -58, -25 };
    byte[] stringResult = { '-', '1', '2', '3', '4', '.', '5', '6', '7', '8', '9' };
    Parser parsedValue = new DoubleParser(value);
    validate(parsedValue, byteResult, stringResult, stringResult);
    validateCreateBinary(byteResult, Oid.FLOAT8, value);
    validateCreateText(stringResult, Oid.FLOAT8, value);
}
Also used : DoubleParser(com.google.cloud.spanner.pgadapter.parsers.DoubleParser) DoubleParser(com.google.cloud.spanner.pgadapter.parsers.DoubleParser) StatementParser(com.google.cloud.spanner.pgadapter.utils.StatementParser) ArrayParser(com.google.cloud.spanner.pgadapter.parsers.ArrayParser) BooleanParser(com.google.cloud.spanner.pgadapter.parsers.BooleanParser) NumericParser(com.google.cloud.spanner.pgadapter.parsers.NumericParser) StringParser(com.google.cloud.spanner.pgadapter.parsers.StringParser) BinaryParser(com.google.cloud.spanner.pgadapter.parsers.BinaryParser) Parser(com.google.cloud.spanner.pgadapter.parsers.Parser) IntegerParser(com.google.cloud.spanner.pgadapter.parsers.IntegerParser) CopyTreeParser(com.google.cloud.spanner.pgadapter.parsers.copy.CopyTreeParser) LongParser(com.google.cloud.spanner.pgadapter.parsers.LongParser) DateParser(com.google.cloud.spanner.pgadapter.parsers.DateParser) TimestampParser(com.google.cloud.spanner.pgadapter.parsers.TimestampParser) Test(org.junit.Test)

Example 10 with Parser

use of com.google.cloud.spanner.pgadapter.parsers.Parser in project pgadapter by GoogleCloudPlatform.

the class ParserTest method testPositiveDoubleParsing.

@Test
public void testPositiveDoubleParsing() {
    double value = 1234.56789d;
    byte[] byteResult = { 64, -109, 74, 69, -124, -12, -58, -25 };
    byte[] stringResult = { '1', '2', '3', '4', '.', '5', '6', '7', '8', '9' };
    Parser parsedValue = new DoubleParser(value);
    validate(parsedValue, byteResult, stringResult, stringResult);
    validateCreateBinary(byteResult, Oid.FLOAT8, value);
    validateCreateText(stringResult, Oid.FLOAT8, value);
}
Also used : DoubleParser(com.google.cloud.spanner.pgadapter.parsers.DoubleParser) DoubleParser(com.google.cloud.spanner.pgadapter.parsers.DoubleParser) StatementParser(com.google.cloud.spanner.pgadapter.utils.StatementParser) ArrayParser(com.google.cloud.spanner.pgadapter.parsers.ArrayParser) BooleanParser(com.google.cloud.spanner.pgadapter.parsers.BooleanParser) NumericParser(com.google.cloud.spanner.pgadapter.parsers.NumericParser) StringParser(com.google.cloud.spanner.pgadapter.parsers.StringParser) BinaryParser(com.google.cloud.spanner.pgadapter.parsers.BinaryParser) Parser(com.google.cloud.spanner.pgadapter.parsers.Parser) IntegerParser(com.google.cloud.spanner.pgadapter.parsers.IntegerParser) CopyTreeParser(com.google.cloud.spanner.pgadapter.parsers.copy.CopyTreeParser) LongParser(com.google.cloud.spanner.pgadapter.parsers.LongParser) DateParser(com.google.cloud.spanner.pgadapter.parsers.DateParser) TimestampParser(com.google.cloud.spanner.pgadapter.parsers.TimestampParser) Test(org.junit.Test)

Aggregations

ArrayParser (com.google.cloud.spanner.pgadapter.parsers.ArrayParser)15 BinaryParser (com.google.cloud.spanner.pgadapter.parsers.BinaryParser)15 BooleanParser (com.google.cloud.spanner.pgadapter.parsers.BooleanParser)15 DateParser (com.google.cloud.spanner.pgadapter.parsers.DateParser)15 DoubleParser (com.google.cloud.spanner.pgadapter.parsers.DoubleParser)15 IntegerParser (com.google.cloud.spanner.pgadapter.parsers.IntegerParser)15 LongParser (com.google.cloud.spanner.pgadapter.parsers.LongParser)15 NumericParser (com.google.cloud.spanner.pgadapter.parsers.NumericParser)15 Parser (com.google.cloud.spanner.pgadapter.parsers.Parser)15 StringParser (com.google.cloud.spanner.pgadapter.parsers.StringParser)15 TimestampParser (com.google.cloud.spanner.pgadapter.parsers.TimestampParser)15 CopyTreeParser (com.google.cloud.spanner.pgadapter.parsers.copy.CopyTreeParser)15 StatementParser (com.google.cloud.spanner.pgadapter.utils.StatementParser)15 Test (org.junit.Test)13 ByteArray (com.google.cloud.ByteArray)1 Date (com.google.cloud.Date)1 Timestamp (com.google.cloud.Timestamp)1 BigDecimal (java.math.BigDecimal)1