89 lines
3.2 KiB
Go
89 lines
3.2 KiB
Go
// 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 (
|
|
"context"
|
|
|
|
"github.com/dolthub/go-mysql-server/sql"
|
|
|
|
"github.com/dolthub/doltgresql/core/id"
|
|
)
|
|
|
|
// NewCompositeType creates new instance of composite DoltgresType.
|
|
func NewCompositeType(_ context.Context, relID id.Id, arrayType *DoltgresType, typeID id.Type, attrs []CompositeAttribute) *DoltgresType {
|
|
if arrayType == nil {
|
|
arrayType = internalNullType
|
|
}
|
|
return &DoltgresType{
|
|
ID: typeID,
|
|
TypLength: -1,
|
|
PassedByVal: false,
|
|
TypType: TypeType_Composite,
|
|
TypCategory: TypeCategory_CompositeTypes,
|
|
IsPreferred: false,
|
|
IsDefined: true,
|
|
Delimiter: ",",
|
|
RelID: relID,
|
|
SubscriptFunc: toFuncID("-"),
|
|
Elem: internalNullType,
|
|
Array: arrayType,
|
|
InputFunc: toFuncID("record_in", toInternal("cstring"), toInternal("oid"), toInternal("int4")),
|
|
OutputFunc: toFuncID("record_out", toInternal("record")),
|
|
ReceiveFunc: toFuncID("record_recv", toInternal("internal"), toInternal("oid"), toInternal("int4")),
|
|
SendFunc: toFuncID("record_send", toInternal("record")),
|
|
ModInFunc: toFuncID("-"),
|
|
ModOutFunc: toFuncID("-"),
|
|
AnalyzeFunc: toFuncID("-"),
|
|
Align: TypeAlignment_Double,
|
|
Storage: TypeStorage_Extended,
|
|
NotNull: false,
|
|
BaseTypeType: internalNullType,
|
|
TypMod: -1,
|
|
NDims: 0,
|
|
TypCollation: id.NullCollation,
|
|
DefaulBin: "",
|
|
Default: "",
|
|
Acl: nil,
|
|
Checks: nil,
|
|
attTypMod: -1,
|
|
CompareFunc: toFuncID("btrecordcmp", toInternal("record"), toInternal("record")),
|
|
CompositeAttrs: attrs,
|
|
SerializationFunc: serializeTypeRecord,
|
|
DeserializationFunc: deserializeTypeRecord,
|
|
}
|
|
}
|
|
|
|
// CompositeAttribute represents a composite type attribute.
|
|
// This is a partial pg_attribute row entry.
|
|
type CompositeAttribute struct {
|
|
RelID id.Id // ID of the relation it belongs to
|
|
Name string
|
|
Type *DoltgresType // ID of DoltgresType
|
|
Num int16 // 1-based number of the column in relation
|
|
Collation string
|
|
}
|
|
|
|
// NewCompositeAttribute creates new instance of composite type attribute. `num` is 1-based rather than 0-based.
|
|
func NewCompositeAttribute(ctx *sql.Context, relID id.Id, name string, typ *DoltgresType, num int16, collation string) CompositeAttribute {
|
|
return CompositeAttribute{
|
|
RelID: relID,
|
|
Name: name,
|
|
Type: typ,
|
|
Num: num,
|
|
Collation: collation,
|
|
}
|
|
}
|