@@ -22,15 +22,15 @@ export function decodeString(
2222 offset : IntWrapper ,
2323 numStreams : number ,
2424 bitVector ?: BitVector ,
25- ) : Vector {
26- let dictionaryLengthStream : Uint32Array = null ;
27- let offsetStream : Uint32Array = null ;
28- let dictionaryStream : Uint8Array = null ;
29- let symbolLengthStream : Uint32Array = null ;
30- let symbolTableStream : Uint8Array = null ;
31- let nullabilityBuffer : BitVector = bitVector ?? null ;
32- let plainLengthStream : Uint32Array = null ;
33- let plainDataStream : Uint8Array = null ;
25+ ) : Vector | undefined {
26+ let dictionaryLengthStream : Uint32Array | undefined ;
27+ let offsetStream : Uint32Array | undefined ;
28+ let dictionaryStream : Uint8Array | undefined ;
29+ let symbolLengthStream : Uint32Array | undefined ;
30+ let symbolTableStream : Uint8Array | undefined ;
31+ let nullabilityBuffer : BitVector | undefined = bitVector ;
32+ let plainLengthStream : Uint32Array | undefined ;
33+ let plainDataStream : Uint8Array | undefined ;
3434
3535 for ( let i = 0 ; i < numStreams ; i ++ ) {
3636 const streamMetadata = decodeStreamMetadata ( data , offset ) ;
@@ -91,15 +91,18 @@ export function decodeString(
9191
9292function decodeFsstDictionaryVector (
9393 name : string ,
94- symbolTableStream : Uint8Array | null ,
95- offsetStream : Uint32Array | null ,
96- dictionaryLengthStream : Uint32Array | null ,
97- dictionaryStream : Uint8Array | null ,
98- symbolLengthStream : Uint32Array | null ,
99- nullabilityBuffer : BitVector | null ,
100- ) : Vector | null {
94+ symbolTableStream : Uint8Array | undefined ,
95+ offsetStream : Uint32Array | undefined ,
96+ dictionaryLengthStream : Uint32Array | undefined ,
97+ dictionaryStream : Uint8Array | undefined ,
98+ symbolLengthStream : Uint32Array | undefined ,
99+ nullabilityBuffer : BitVector | undefined ,
100+ ) : Vector | undefined {
101101 if ( ! symbolTableStream ) {
102- return null ;
102+ return undefined ;
103+ }
104+ if ( ! offsetStream || ! dictionaryLengthStream || ! dictionaryStream || ! symbolLengthStream ) {
105+ throw new Error ( `Incomplete FSST dictionary string column "${ name } "` ) ;
103106 }
104107 return new StringFsstDictionaryVector (
105108 name ,
@@ -114,13 +117,16 @@ function decodeFsstDictionaryVector(
114117
115118function decodeDictionaryVector (
116119 name : string ,
117- dictionaryStream : Uint8Array | null ,
118- offsetStream : Uint32Array | null ,
119- dictionaryLengthStream : Uint32Array | null ,
120- nullabilityBuffer : BitVector | null ,
121- ) : Vector | null {
120+ dictionaryStream : Uint8Array | undefined ,
121+ offsetStream : Uint32Array | undefined ,
122+ dictionaryLengthStream : Uint32Array | undefined ,
123+ nullabilityBuffer : BitVector | undefined ,
124+ ) : Vector | undefined {
122125 if ( ! dictionaryStream ) {
123- return null ;
126+ return undefined ;
127+ }
128+ if ( ! offsetStream || ! dictionaryLengthStream ) {
129+ throw new Error ( `Incomplete dictionary string column "${ name } "` ) ;
124130 }
125131 return nullabilityBuffer
126132 ? new StringDictionaryVector ( name , offsetStream , dictionaryLengthStream , dictionaryStream , nullabilityBuffer )
@@ -129,13 +135,13 @@ function decodeDictionaryVector(
129135
130136function decodePlainStringVector (
131137 name : string ,
132- plainLengthStream : Uint32Array | null ,
133- plainDataStream : Uint8Array | null ,
134- offsetStream : Uint32Array | null ,
135- nullabilityBuffer : BitVector | null ,
136- ) : Vector | null {
138+ plainLengthStream : Uint32Array | undefined ,
139+ plainDataStream : Uint8Array | undefined ,
140+ offsetStream : Uint32Array | undefined ,
141+ nullabilityBuffer : BitVector | undefined ,
142+ ) : Vector | undefined {
137143 if ( ! plainLengthStream || ! plainDataStream ) {
138- return null ;
144+ return undefined ;
139145 }
140146
141147 if ( offsetStream ) {
@@ -174,10 +180,10 @@ export function decodeSharedDictionary(
174180 column : Column ,
175181 propertyColumnNames ?: Set < string > ,
176182) : Vector [ ] {
177- let dictionaryOffsetBuffer : Uint32Array = null ;
178- let dictionaryBuffer : Uint8Array = null ;
179- let symbolOffsetBuffer : Uint32Array = null ;
180- let symbolTableBuffer : Uint8Array = null ;
183+ let dictionaryOffsetBuffer : Uint32Array | undefined ;
184+ let dictionaryBuffer : Uint8Array | undefined ;
185+ let symbolOffsetBuffer : Uint32Array | undefined ;
186+ let symbolTableBuffer : Uint8Array | undefined ;
181187
182188 let dictionaryStreamDecoded = false ;
183189 while ( ! dictionaryStreamDecoded ) {
@@ -205,6 +211,12 @@ export function decodeSharedDictionary(
205211 }
206212 }
207213
214+ if ( column . type !== "complexType" ) {
215+ throw new Error ( `Shared dictionary column ${ column . name } must be a complex (struct) column.` ) ;
216+ }
217+ if ( ! dictionaryOffsetBuffer || ! dictionaryBuffer ) {
218+ throw new Error ( `Incomplete shared dictionary for column "${ column . name } "` ) ;
219+ }
208220 const childFields = column . complexType . children ;
209221 const stringDictionaryVectors = [ ] ;
210222 /** Shared by every FSST child-column vector in this SharedDict and populated on first access. */
@@ -255,24 +267,29 @@ export function decodeSharedDictionary(
255267 presentStreamBitVector ,
256268 ) ;
257269
258- stringDictionaryVectors [ i ++ ] = symbolTableBuffer
259- ? new StringFsstDictionaryVector (
260- columnName ,
261- offsetStream ,
262- dictionaryOffsetBuffer ,
263- dictionaryBuffer ,
264- symbolOffsetBuffer ,
265- symbolTableBuffer ,
266- presentStreamBitVector ,
267- sharedDictionaryCache ,
268- )
269- : new StringDictionaryVector (
270- columnName ,
271- offsetStream ,
272- dictionaryOffsetBuffer ,
273- dictionaryBuffer ,
274- presentStreamBitVector ,
275- ) ;
270+ if ( symbolTableBuffer ) {
271+ if ( ! symbolOffsetBuffer ) {
272+ throw new Error ( `Incomplete shared FSST dictionary for column "${ columnName } "` ) ;
273+ }
274+ stringDictionaryVectors [ i ++ ] = new StringFsstDictionaryVector (
275+ columnName ,
276+ offsetStream ,
277+ dictionaryOffsetBuffer ,
278+ dictionaryBuffer ,
279+ symbolOffsetBuffer ,
280+ symbolTableBuffer ,
281+ presentStreamBitVector ,
282+ sharedDictionaryCache ,
283+ ) ;
284+ } else {
285+ stringDictionaryVectors [ i ++ ] = new StringDictionaryVector (
286+ columnName ,
287+ offsetStream ,
288+ dictionaryOffsetBuffer ,
289+ dictionaryBuffer ,
290+ presentStreamBitVector ,
291+ ) ;
292+ }
276293 }
277294
278295 return stringDictionaryVectors ;
0 commit comments