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

release-20.1: pgwire: remove left over types refactor artifact #52351

Merged
merged 1 commit into from Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/sql/pgwire/command_result.go
Expand Up @@ -219,7 +219,7 @@ func (r *commandResult) SetColumns(ctx context.Context, cols sqlbase.ResultColum
}
r.oids = make([]oid.Oid, len(cols))
for i, col := range cols {
r.oids[i] = mapResultOid(col.Typ.Oid())
r.oids[i] = col.Typ.Oid()
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/pgwire/conn.go
Expand Up @@ -1277,7 +1277,7 @@ func (c *conn) writeRowDescription(
typ := pgTypeForParserType(column.Typ)
c.msgBuilder.putInt32(int32(column.TableID)) // Table OID (optional).
c.msgBuilder.putInt16(int16(column.PGAttributeNum)) // Column attribute ID (optional).
c.msgBuilder.putInt32(int32(mapResultOid(typ.oid)))
c.msgBuilder.putInt32(int32(typ.oid))
c.msgBuilder.putInt16(int16(typ.size))
c.msgBuilder.putInt32(column.GetTypeModifier()) // Type modifier
if formatCodes == nil {
Expand Down
42 changes: 41 additions & 1 deletion pkg/sql/pgwire/testdata/pgtest/row_description
Expand Up @@ -115,7 +115,47 @@ Query {"String": "SELECT b FROM tab3"}
until
ReadyForQuery
----
{"Type":"RowDescription","Fields":[{"Name":"b","TableOID":58,"TableAttributeNumber":2,"DataTypeOID":25,"DataTypeSize":-1,"TypeModifier":12,"Format":0}]}
{"Type":"RowDescription","Fields":[{"Name":"b","TableOID":58,"TableAttributeNumber":2,"DataTypeOID":1042,"DataTypeSize":-1,"TypeModifier":12,"Format":0}]}
{"Type":"DataRow","Values":[{"text":"hello"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}

# tab4 is a regression test for #51360
send
Query {"String": "CREATE TABLE tab4 (a INT8 PRIMARY KEY, b VARCHAR(256)[] NOT NULL)"}
----

until
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"CREATE TABLE"}
{"Type":"ReadyForQuery","TxStatus":"I"}

send
Query {"String": "INSERT INTO tab4 VALUES(4, ARRAY['hello', 'goodbye'])"}
----

until
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"INSERT 0 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}

# 80 = ASCII 'P' for Portal
send
Parse {"Name": "s", "Query": "SELECT b FROM tab4"}
Bind {"DestinationPortal": "p", "PreparedStatement": "s"}
Describe {"ObjectType": 80, "Name": "p"}
Execute {"Portal": "p"}
Sync
----

until
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"RowDescription","Fields":[{"Name":"b","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":1015,"DataTypeSize":-1,"TypeModifier":-1,"Format":0}]}
{"Type":"DataRow","Values":[{"text":"{hello,goodbye}"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}
24 changes: 0 additions & 24 deletions pkg/sql/pgwire/types.go
Expand Up @@ -64,30 +64,6 @@ func pgTypeForParserType(t *types.T) pgType {
}
}

var resultOidMap = map[oid.Oid]oid.Oid{
oid.T_bit: oid.T_varbit,
oid.T__bit: oid.T__varbit,
oid.T_bpchar: oid.T_text,
oid.T__bpchar: oid.T__text,
oid.T_char: oid.T_text,
oid.T__char: oid.T__text,
oid.T_varchar: oid.T_text,
oid.T__varchar: oid.T__text,
}

// mapResultOid maps an Oid value returned by the server to an Oid value that is
// backwards-compatible with previous versions of CRDB. See this issue for more
// details: https://github.com/cockroachdb/cockroach/issues/36811
//
// TODO(andyk): Remove this once issue #36811 is resolved.
func mapResultOid(o oid.Oid) oid.Oid {
mapped := resultOidMap[o]
if mapped != 0 {
return mapped
}
return o
}

func (b *writeBuffer) writeTextDatum(
ctx context.Context, d tree.Datum, conv sessiondata.DataConversionConfig,
) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/testutils/pgtest/datadriven.go
Expand Up @@ -162,6 +162,8 @@ func toMessage(typ string) interface{} {
return &pgproto3.CommandComplete{}
case "DataRow":
return &pgproto3.DataRow{}
case "Describe":
return &pgproto3.Describe{}
case "ErrorResponse":
return &pgproto3.ErrorResponse{}
case "Execute":
Expand Down