-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
any_array.go
162 lines (131 loc) · 5.12 KB
/
any_array.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"fmt"
"math"
"reflect"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/types"
"github.com/dolthub/vitess/go/sqltypes"
"github.com/dolthub/vitess/go/vt/proto/query"
"github.com/lib/pq/oid"
)
// AnyArray is an array that may contain elements of any type.
var AnyArray = AnyArrayType{}
// AnyArrayType is the extended type implementation of the PostgreSQL anyarray.
type AnyArrayType struct{}
var _ DoltgresType = AnyArrayType{}
var _ DoltgresArrayType = AnyArrayType{}
// BaseID implements the DoltgresType interface.
func (aa AnyArrayType) BaseID() DoltgresTypeBaseID {
return DoltgresTypeBaseID_AnyArray
}
// BaseType implements the DoltgresArrayType interface.
func (aa AnyArrayType) BaseType() DoltgresType {
return Unknown
}
// CollationCoercibility implements the DoltgresType interface.
func (aa AnyArrayType) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
return sql.Collation_binary, 5
}
// Compare implements the DoltgresType interface.
func (aa AnyArrayType) Compare(v1 any, v2 any) (int, error) {
return 0, fmt.Errorf("%s cannot compare values", aa.String())
}
// Convert implements the DoltgresType interface.
func (aa AnyArrayType) Convert(val any) (any, sql.ConvertInRange, error) {
return nil, sql.OutOfRange, fmt.Errorf("%s cannot convert values", aa.String())
}
// Equals implements the DoltgresType interface.
func (aa AnyArrayType) Equals(otherType sql.Type) bool {
_, ok := otherType.(AnyArrayType)
return ok
}
// FormatSerializedValue implements the DoltgresType interface.
func (aa AnyArrayType) FormatSerializedValue(val []byte) (string, error) {
return "", fmt.Errorf("%s cannot format serialized values", aa.String())
}
// FormatValue implements the DoltgresType interface.
func (aa AnyArrayType) FormatValue(val any) (string, error) {
return "", fmt.Errorf("%s cannot format values", aa.String())
}
// GetSerializationID implements the DoltgresType interface.
func (aa AnyArrayType) GetSerializationID() SerializationID {
return SerializationID_Invalid
}
// IsUnbounded implements the DoltgresType interface.
func (aa AnyArrayType) IsUnbounded() bool {
return true
}
// MaxSerializedWidth implements the DoltgresType interface.
func (aa AnyArrayType) MaxSerializedWidth() types.ExtendedTypeSerializedWidth {
return types.ExtendedTypeSerializedWidth_Unbounded
}
// MaxTextResponseByteLength implements the DoltgresType interface.
func (aa AnyArrayType) MaxTextResponseByteLength(ctx *sql.Context) uint32 {
return math.MaxUint32
}
// OID implements the DoltgresType interface.
func (aa AnyArrayType) OID() uint32 {
return uint32(oid.T_anyarray)
}
// Promote implements the DoltgresType interface.
func (aa AnyArrayType) Promote() sql.Type {
return aa
}
// SerializedCompare implements the DoltgresType interface.
func (aa AnyArrayType) SerializedCompare(v1 []byte, v2 []byte) (int, error) {
return 0, fmt.Errorf("%s cannot compare serialized values", aa.String())
}
// SQL implements the DoltgresType interface.
func (aa AnyArrayType) SQL(ctx *sql.Context, dest []byte, v any) (sqltypes.Value, error) {
return sqltypes.Value{}, fmt.Errorf("%s cannot output values in the wire format", aa.String())
}
// String implements the DoltgresType interface.
func (aa AnyArrayType) String() string {
return "anyarray"
}
// ToArrayType implements the DoltgresType interface.
func (aa AnyArrayType) ToArrayType() DoltgresArrayType {
return aa
}
// Type implements the DoltgresType interface.
func (aa AnyArrayType) Type() query.Type {
return sqltypes.Text
}
// ValueType implements the DoltgresType interface.
func (aa AnyArrayType) ValueType() reflect.Type {
return reflect.TypeOf([]any{})
}
// Zero implements the DoltgresType interface.
func (aa AnyArrayType) Zero() any {
return []any{}
}
// SerializeType implements the DoltgresType interface.
func (aa AnyArrayType) SerializeType() ([]byte, error) {
return nil, fmt.Errorf("%s cannot be serialized", aa.String())
}
// deserializeType implements the DoltgresType interface.
func (aa AnyArrayType) deserializeType(version uint16, metadata []byte) (DoltgresType, error) {
return nil, fmt.Errorf("%s cannot be deserialized", aa.String())
}
// SerializeValue implements the DoltgresType interface.
func (aa AnyArrayType) SerializeValue(val any) ([]byte, error) {
return nil, fmt.Errorf("%s cannot serialize values", aa.String())
}
// DeserializeValue implements the DoltgresType interface.
func (aa AnyArrayType) DeserializeValue(val []byte) (any, error) {
return nil, fmt.Errorf("%s cannot deserialize values", aa.String())
}