Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] sql: test decimals in pgwire binary format #57049

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/cmd/generate-binary/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ var inputs = map[string][]string{
"42.0",
"420000",
"420000.0",
"10000",
"1E+4",
},

"'%s'::float8": {
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/pgwire/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func readEncodingTests(t testing.TB) []*encodingTest {
if err != nil {
t.Fatal(err)
}
if tc.SQL == "'1E+4'::decimal" {
fmt.Println()
}
d, err := te.Eval(&evalCtx)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -156,6 +159,9 @@ func TestEncodings(t *testing.T) {
t.Run(pgwirebase.FormatBinary.String(), func(t *testing.T) {
for _, tc := range tests {
d := tc.Datum
if tc.SQL == "'1E+4'::decimal" {
fmt.Println()
}
buf.reset()
buf.writeBinaryDatum(ctx, d, time.UTC, tc.T)
if buf.err != nil {
Expand Down Expand Up @@ -218,6 +224,11 @@ func TestExoticNumericEncodings(t *testing.T) {
{apd.New(0, 0), []byte{0, 0, 0, 0, 0, 0, 0, 0}},
{apd.New(0, 0), []byte{0, 1, 0, 0, 0, 0, 0, 0, 0, 0}},
{apd.New(10000, 0), []byte{0, 2, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0}},
{apd.New(10000, 0), []byte{0, 1, 0, 1, 0, 0, 0, 0, 0, 1}},
{apd.New(10000, 0), []byte{00, 0x01, 00, 01, 00, 00, 0xff, 0xfc, 00, 0x01}},
{apd.New(1, 4), []byte{0, 2, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0}},
{apd.New(1, 4), []byte{0, 1, 0, 1, 0, 0, 0, 0, 0, 1}},
{apd.New(1, 4), []byte{00, 0x01, 00, 01, 00, 00, 0xff, 0xfc, 00, 0x01}},
{apd.New(10001, 0), []byte{0, 2, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1}},
{apd.New(1000000, 0), []byte{0, 2, 0, 1, 0, 0, 0, 0, 0, 100, 0, 0}},
{apd.New(1000001, 0), []byte{0, 2, 0, 1, 0, 0, 0, 0, 0, 100, 0, 1}},
Expand Down
34 changes: 24 additions & 10 deletions pkg/sql/pgwire/testdata/encodings.json
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,20 @@
"TextAsBinary": [52, 50, 48, 48, 48, 48, 46, 48],
"Binary": [0, 1, 0, 1, 0, 0, 0, 1, 0, 42]
},
{
"SQL": "'10000'::decimal",
"Oid": 1700,
"Text": "10000",
"TextAsBinary": [49, 48, 48, 48, 48],
"Binary": [0, 1, 0, 1, 0, 0, 0, 0, 0, 1]
},
{
"SQL": "'1E+4'::decimal",
"Oid": 1700,
"Text": "10000",
"TextAsBinary": [49, 48, 48, 48, 48],
"Binary": [0, 1, 0, 1, 0, 0, 0, 0, 0, 1]
},
{
"SQL": "'{-000.000,-0000021234.23246346000000,-1.2,.0,.1,.1234}'::decimal[]",
"Oid": 1231,
Expand Down Expand Up @@ -702,8 +716,8 @@
{
"SQL": "'1.4013e-45'::float4",
"Oid": 700,
"Text": "1.4013e-45",
"TextAsBinary": [49, 46, 52, 48, 49, 51, 101, 45, 52, 53],
"Text": "1e-45",
"TextAsBinary": [49, 101, 45, 52, 53],
"Binary": [0, 0, 0, 1]
},
{
Expand Down Expand Up @@ -758,29 +772,29 @@
{
"SQL": "'3.4028234663852886e+38'::float8",
"Oid": 701,
"Text": "3.40282346638529e+38",
"TextAsBinary": [51, 46, 52, 48, 50, 56, 50, 51, 52, 54, 54, 51, 56, 53, 50, 57, 101, 43, 51, 56],
"Text": "3.4028234663852886e+38",
"TextAsBinary": [51, 46, 52, 48, 50, 56, 50, 51, 52, 54, 54, 51, 56, 53, 50, 56, 56, 54, 101, 43, 51, 56],
"Binary": [71, 239, 255, 255, 224, 0, 0, 0]
},
{
"SQL": "'1.401298464324817e-45'::float8",
"Oid": 701,
"Text": "1.40129846432482e-45",
"TextAsBinary": [49, 46, 52, 48, 49, 50, 57, 56, 52, 54, 52, 51, 50, 52, 56, 50, 101, 45, 52, 53],
"Text": "1.401298464324817e-45",
"TextAsBinary": [49, 46, 52, 48, 49, 50, 57, 56, 52, 54, 52, 51, 50, 52, 56, 49, 55, 101, 45, 52, 53],
"Binary": [54, 160, 0, 0, 0, 0, 0, 0]
},
{
"SQL": "'1.7976931348623157e+308'::float8",
"Oid": 701,
"Text": "1.79769313486232e+308",
"TextAsBinary": [49, 46, 55, 57, 55, 54, 57, 51, 49, 51, 52, 56, 54, 50, 51, 50, 101, 43, 51, 48, 56],
"Text": "1.7976931348623157e+308",
"TextAsBinary": [49, 46, 55, 57, 55, 54, 57, 51, 49, 51, 52, 56, 54, 50, 51, 49, 53, 55, 101, 43, 51, 48, 56],
"Binary": [127, 239, 255, 255, 255, 255, 255, 255]
},
{
"SQL": "'5e-324'::float8",
"Oid": 701,
"Text": "4.94065645841247e-324",
"TextAsBinary": [52, 46, 57, 52, 48, 54, 53, 54, 52, 53, 56, 52, 49, 50, 52, 55, 101, 45, 51, 50, 52],
"Text": "5e-324",
"TextAsBinary": [53, 101, 45, 51, 50, 52],
"Binary": [0, 0, 0, 0, 0, 0, 0, 1]
},
{
Expand Down
66 changes: 66 additions & 0 deletions pkg/sql/pgwire/testdata/pgtest/decimal
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,69 @@ ReadyForQuery
{"Type":"DataRow","Values":[{"text":"0"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}

send
Parse {"Name": "s1", "Query": "SELECT 1E+4::decimal, $1::decimal"}
Bind {"DestinationPortal": "p1", "PreparedStatement": "s1", "ParameterFormatCodes": [1], "Parameters": [[0, 1, 0, 1, 0, 0, 0, 0, 0, 1]]}
Execute {"Portal": "p1"}
Sync
----

until
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"DataRow","Values":[{"text":"10000"},{"text":"10000"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}

# ResultFormatCodes [1] = FormatBinary
send
Parse {"Name": "s2", "Query": "SELECT 10000::decimal, $1::decimal"}
Bind {"DestinationPortal": "p2", "PreparedStatement": "s2", "ParameterFormatCodes": [1], "Parameters": [[0, 1, 0, 1, 0, 0, 0, 0, 0, 1]], "ResultFormatCodes": [1,1]}
Execute {"Portal": "p2"}
Sync
----

until
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"DataRow","Values":[{"binary":"00010001000000000001"},{"binary":"00010001000000000001"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}

# ResultFormatCodes [1] = FormatBinary
send
Parse {"Name": "s3", "Query": "SELECT 10000::decimal, $1::decimal"}
Bind {"DestinationPortal": "p3", "PreparedStatement": "s3", "ParameterFormatCodes": [1], "Parameters": [[0, 1, 0, 1, 0, 0, 255, 252, 0, 1]], "ResultFormatCodes": [1,1]}
Execute {"Portal": "p3"}
Sync
----

until
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"DataRow","Values":[{"binary":"00010001000000000001"},{"binary":"00010001000000000001"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}

send
Parse {"Name": "s4", "Query": "SELECT 1E+4::decimal, $1::decimal"}
Bind {"DestinationPortal": "p4", "PreparedStatement": "s4", "ParameterFormatCodes": [1], "Parameters": [[0, 2, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0]]}
Execute {"Portal": "p4"}
Sync
----

until
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"DataRow","Values":[{"text":"10000"},{"text":"10000"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}
3 changes: 3 additions & 0 deletions pkg/testutils/pgtest/datadriven.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func RunTest(t *testing.T, path, addr, user string) {
if err != nil {
t.Fatal(err)
}
if !strings.Contains(path, "decimal") {
return
}
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
switch d.Cmd {
case "only":
Expand Down