// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you 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. import * as type from '../type.js'; import { Visitor } from '../visitor.js'; import { Type as ArrowType } from '../fb/type.js'; import { Precision, DateUnit, TimeUnit, IntervalUnit, UnionMode } from '../enum.js'; /** @ignore */ export interface JSONTypeAssembler extends Visitor { visit(node: T): Record | undefined; } /** @ignore */ export class JSONTypeAssembler extends Visitor { public visit(node: T): Record | undefined { return node == null ? undefined : super.visit(node); } public visitNull({ typeId }: T) { return { 'name': ArrowType[typeId].toLowerCase() }; } public visitInt({ typeId, bitWidth, isSigned }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'bitWidth': bitWidth, 'isSigned': isSigned }; } public visitFloat({ typeId, precision }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'precision': Precision[precision] }; } public visitBinary({ typeId }: T) { return { 'name': ArrowType[typeId].toLowerCase() }; } public visitBool({ typeId }: T) { return { 'name': ArrowType[typeId].toLowerCase() }; } public visitUtf8({ typeId }: T) { return { 'name': ArrowType[typeId].toLowerCase() }; } public visitDecimal({ typeId, scale, precision, bitWidth }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'scale': scale, 'precision': precision, 'bitWidth': bitWidth }; } public visitDate({ typeId, unit }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'unit': DateUnit[unit] }; } public visitTime({ typeId, unit, bitWidth }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'unit': TimeUnit[unit], bitWidth }; } public visitTimestamp({ typeId, timezone, unit }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'unit': TimeUnit[unit], timezone }; } public visitInterval({ typeId, unit }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'unit': IntervalUnit[unit] }; } public visitList({ typeId }: T) { return { 'name': ArrowType[typeId].toLowerCase() }; } public visitStruct({ typeId }: T) { return { 'name': ArrowType[typeId].toLowerCase() }; } public visitUnion({ typeId, mode, typeIds }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'mode': UnionMode[mode], 'typeIds': [...typeIds] }; } public visitDictionary(node: T) { return this.visit(node.dictionary); } public visitFixedSizeBinary({ typeId, byteWidth }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'byteWidth': byteWidth }; } public visitFixedSizeList({ typeId, listSize }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'listSize': listSize }; } public visitMap({ typeId, keysSorted }: T) { return { 'name': ArrowType[typeId].toLowerCase(), 'keysSorted': keysSorted }; } }