Search in sources :

Example 1 with Parser

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

the class ParserTest method validateCreateText.

private void validateCreateText(byte[] item, int oid, Object value) {
    Parser text = Parser.create(item, oid, FormatCode.TEXT);
    assertParserValueEqual(text, value);
}
Also used : 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)

Example 2 with Parser

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

the class ParserTest method testNumericParsing.

@Test
public void testNumericParsing() {
    BigDecimal value = new BigDecimal("1234567890.1234567890");
    byte[] byteResult = ByteConverter.numeric(new BigDecimal("1234567890.1234567890"));
    byte[] stringResult = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
    Parser parser = new NumericParser(value);
    validate(parser, byteResult, stringResult, stringResult);
    assertThat(parser.getItem(), is(equalTo(value)));
    validateCreateBinary(byteResult, Oid.NUMERIC, value);
    validateCreateText(stringResult, Oid.NUMERIC, value);
}
Also used : NumericParser(com.google.cloud.spanner.pgadapter.parsers.NumericParser) BigDecimal(java.math.BigDecimal) 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 3 with Parser

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

the class ParserTest method testPositiveLongParsing.

@Test
public void testPositiveLongParsing() {
    long value = 1234567890L;
    byte[] byteResult = { 0, 0, 0, 0, 73, -106, 2, -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 4 with Parser

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

the class ParserTest method validateCreateBinary.

private void validateCreateBinary(byte[] item, int oid, Object value) {
    Parser binary = Parser.create(item, oid, FormatCode.BINARY);
    assertParserValueEqual(binary, value);
}
Also used : 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)

Example 5 with Parser

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

the class ParserTest method testPositiveIntegerParsing.

@Test
public void testPositiveIntegerParsing() {
    int value = 1234567890;
    byte[] byteResult = { 73, -106, 2, -46 };
    byte[] stringResult = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
    Parser parsedValue = new IntegerParser(value);
    validate(parsedValue, byteResult, stringResult, stringResult);
    validateCreateBinary(byteResult, Oid.INT4, value);
    validateCreateText(stringResult, Oid.INT4, value);
}
Also used : 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) IntegerParser(com.google.cloud.spanner.pgadapter.parsers.IntegerParser) 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