Search in sources :

Example 11 with Parser

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

the class ParserTest method testNegativeIntegerParsing.

@Test
public void testNegativeIntegerParsing() {
    int value = -1234567890;
    byte[] byteResult = { -74, 105, -3, 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)

Example 12 with Parser

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

the class ParserTest method testFalseBooleanParsing.

@Test
public void testFalseBooleanParsing() {
    boolean value = false;
    byte[] byteResult = { 0 };
    byte[] stringResult = { 'f' };
    byte[] spannerResult = { 'f', 'a', 'l', 's', 'e' };
    Parser parsedValue = new BooleanParser(value);
    validate(parsedValue, byteResult, stringResult, spannerResult);
    validateCreateBinary(byteResult, Oid.BIT, value);
    validateCreateText(stringResult, Oid.BIT, value);
}
Also used : BooleanParser(com.google.cloud.spanner.pgadapter.parsers.BooleanParser) 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 13 with Parser

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

the class ParserTest method testTrueBooleanParsing.

@Test
public void testTrueBooleanParsing() {
    boolean value = true;
    byte[] byteResult = { 1 };
    byte[] stringResult = { 't' };
    byte[] spannerResult = { 't', 'r', 'u', 'e' };
    Parser parsedValue = new BooleanParser(value);
    validate(parsedValue, byteResult, stringResult, spannerResult);
    validateCreateBinary(byteResult, Oid.BIT, value);
    validateCreateText(stringResult, Oid.BIT, value);
}
Also used : BooleanParser(com.google.cloud.spanner.pgadapter.parsers.BooleanParser) 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 14 with Parser

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

the class ParserTest method testTimestampParsingBytePart.

@Test
public void testTimestampParsingBytePart() {
    Timestamp value = Timestamp.ofTimeMicroseconds(904910400000000L);
    byte[] byteResult = { -1, -1, -38, 1, -93, -70, 48, 0 };
    Parser parsedValue = new TimestampParser(value);
    assertThat(parsedValue.parse(DataFormat.POSTGRESQL_BINARY), is(equalTo(byteResult)));
    validateCreateBinary(byteResult, Oid.TIMESTAMP, value);
}
Also used : TimestampParser(com.google.cloud.spanner.pgadapter.parsers.TimestampParser) Timestamp(com.google.cloud.Timestamp) 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 15 with Parser

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

the class ParserTest method testDateParsing.

@Test
public void testDateParsing() {
    // Google founding date :)
    Date value = Date.fromYearMonthDay(1998, 9, 4);
    byte[] byteResult = { -1, -1, -2, 28 };
    byte[] stringResult = { '1', '9', '9', '8', '-', '0', '9', '-', '0', '4' };
    Parser parsedValue = new DateParser(value);
    validate(parsedValue, byteResult, stringResult, stringResult);
    validateCreateBinary(byteResult, Oid.DATE, value);
    validateCreateText(stringResult, Oid.DATE, value);
}
Also used : DateParser(com.google.cloud.spanner.pgadapter.parsers.DateParser) Date(com.google.cloud.Date) 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