CreateArrayTypeFromBaseType create array type from given type. This also sets the `Array` on the given base type if it has not already been set.
(baseType *DoltgresType)
| 28 | // CreateArrayTypeFromBaseType create array type from given type. This also sets the `Array` on the given base type if |
| 29 | // it has not already been set. |
| 30 | func CreateArrayTypeFromBaseType(baseType *DoltgresType) *DoltgresType { |
| 31 | align := TypeAlignment_Int |
| 32 | if baseType.Align == TypeAlignment_Double { |
| 33 | align = TypeAlignment_Double |
| 34 | } |
| 35 | var arrayID id.Type |
| 36 | if baseType.Array == nil || baseType.Array == internalNullType || baseType.Array.ID == id.NullType { |
| 37 | arrayID = id.NewType(baseType.ID.SchemaName(), "_"+baseType.ID.TypeName()) |
| 38 | } else { |
| 39 | arrayID = baseType.Array.ID |
| 40 | } |
| 41 | arrayType := &DoltgresType{ |
| 42 | ID: arrayID, |
| 43 | TypLength: int16(-1), |
| 44 | PassedByVal: false, |
| 45 | TypType: TypeType_Base, |
| 46 | TypCategory: TypeCategory_ArrayTypes, |
| 47 | IsPreferred: false, |
| 48 | IsDefined: true, |
| 49 | Delimiter: ",", |
| 50 | RelID: id.Null, |
| 51 | SubscriptFunc: toFuncID("array_subscript_handler", toInternal("internal")), |
| 52 | Elem: baseType, |
| 53 | Array: internalNullType, |
| 54 | InputFunc: toFuncID("array_in", toInternal("cstring"), toInternal("oid"), toInternal("int4")), |
| 55 | OutputFunc: toFuncID("array_out", toInternal("anyarray")), |
| 56 | ReceiveFunc: toFuncID("array_recv", toInternal("internal"), toInternal("oid"), toInternal("int4")), |
| 57 | SendFunc: toFuncID("array_send", toInternal("anyarray")), |
| 58 | ModInFunc: baseType.ModInFunc, |
| 59 | ModOutFunc: baseType.ModOutFunc, |
| 60 | AnalyzeFunc: toFuncID("array_typanalyze", toInternal("internal")), |
| 61 | Align: align, |
| 62 | Storage: TypeStorage_Extended, |
| 63 | NotNull: false, |
| 64 | BaseTypeType: internalNullType, |
| 65 | TypMod: -1, |
| 66 | NDims: 0, |
| 67 | TypCollation: baseType.TypCollation, |
| 68 | DefaulBin: "", |
| 69 | Default: "", |
| 70 | Acl: nil, |
| 71 | Checks: nil, |
| 72 | InternalName: fmt.Sprintf("%s[]", baseType.Name()), // This will be set to the proper name in ToArrayType |
| 73 | attTypMod: baseType.attTypMod, // TODO: check |
| 74 | CompareFunc: toFuncID("btarraycmp", toInternal("anyarray"), toInternal("anyarray")), |
| 75 | SerializationFunc: serializeTypeArray, |
| 76 | DeserializationFunc: deserializeTypeArray, |
| 77 | } |
| 78 | if baseType.Array == nil || baseType.Array == internalNullType || baseType.Array.ID == id.NullType { |
| 79 | baseType.Array = arrayType |
| 80 | } |
| 81 | return arrayType |
| 82 | } |
| 83 | |
| 84 | // serializeTypeArray handles serialization from the standard representation to our serialized representation that is |
| 85 | // written in Dolt. |
no test coverage detected