This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 6caab7c  ARROW-3425: [JS] Programmatically created dictionary vectors 
don't get dictionary IDs
6caab7c is described below

commit 6caab7c792956a42ac7d14a7ec3b577fa9818fbe
Author: Brian Hulette <[email protected]>
AuthorDate: Thu Oct 11 05:17:02 2018 -0400

    ARROW-3425: [JS] Programmatically created dictionary vectors don't get 
dictionary IDs
    
    Author: Brian Hulette <[email protected]>
    
    Closes #2726 from TheNeuralBit/fix-dictionary-test and squashes the 
following commits:
    
    9a848c6a7 <Brian Hulette> Fix IDs for programmatically generated dictionary 
vecs
    77b569a27 <Brian Hulette> Add (failing) round-trip to table-tests
---
 js/src/type.ts              | 15 ++++++++++++++-
 js/test/jest-extensions.ts  |  1 +
 js/test/unit/table-tests.ts | 17 ++++++++++++++++-
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/js/src/type.ts b/js/src/type.ts
index 26686c7..f8493e4 100644
--- a/js/src/type.ts
+++ b/js/src/type.ts
@@ -33,6 +33,19 @@ export import IntervalUnit = 
Schema_.org.apache.arrow.flatbuf.IntervalUnit;
 export import MessageHeader = Message_.org.apache.arrow.flatbuf.MessageHeader;
 export import MetadataVersion = 
Schema_.org.apache.arrow.flatbuf.MetadataVersion;
 
+function generateDictionaryMap(fields: Field[]) {
+    const result: Map<number, Field<Dictionary>> = new Map();
+    fields
+        .filter((f) => f.type instanceof Dictionary)
+        .forEach((f) => {
+            if (result.has((f.type as Dictionary).id)) {
+                throw new Error(`Cannot create Schema containing two 
dictionaries with the same ID`);
+            }
+            result.set((f.type as Dictionary).id, f as Field<Dictionary>);
+        });
+    return result;
+}
+
 export class Schema {
     public static from(vectors: Vector[]) {
         return new Schema(vectors.map((v, i) => new Field('' + i, v.type)));
@@ -48,7 +61,7 @@ export class Schema {
     constructor(fields: Field[],
                 metadata?: Map<string, string>,
                 version: MetadataVersion = MetadataVersion.V4,
-                dictionaries: Map<number, Field<Dictionary>> = new Map()) {
+                dictionaries: Map<number, Field<Dictionary>> = 
generateDictionaryMap(fields)) {
         this.fields = fields;
         this.version = version;
         this.metadata = metadata;
diff --git a/js/test/jest-extensions.ts b/js/test/jest-extensions.ts
index f45b70c..f309777 100644
--- a/js/test/jest-extensions.ts
+++ b/js/test/jest-extensions.ts
@@ -71,4 +71,5 @@ expect.extend({
             ].join('\n')
         };
     }
+}
 });
diff --git a/js/test/unit/table-tests.ts b/js/test/unit/table-tests.ts
index 6ec5b74..4ee1411 100644
--- a/js/test/unit/table-tests.ts
+++ b/js/test/unit/table-tests.ts
@@ -15,6 +15,8 @@
 // specific language governing permissions and limitations
 // under the License.
 
+import '../jest-extensions';
+
 import Arrow, { vector, RecordBatch } from '../Arrow';
 
 const { predicate, Table } = Arrow;
@@ -66,6 +68,16 @@ const test_data = [
     },
 ];
 
+function compareTables(t1: Table, t2, Table) {
+    expect(t1.length).toEqual(t2.length);
+    expect(t1.numCols).toEqual(t2.numCols);
+    for (let i = -1, n = t1.numCols; ++i < n;) {
+        const v1 = t1.getColumnAt(i);
+        const v2 = t2.getColumnAt(i);
+        (expect([v1, `left`, t1.schema.fields[i].name]) as 
any).toEqualVector([v2, `right`, t2.schema.fields[i].name]);
+    }
+}
+
 describe(`Table`, () => {
     test(`can create an empty table`, () => {
         expect(Table.empty().length).toEqual(0);
@@ -295,6 +307,9 @@ describe(`Table`, () => {
                     
expect(table.filter(col('dictionary').eq(col('dictionary'))).count()).toEqual(table.length);
                 });
             });
+            describe(`serialize and de-serialize is a no-op`, () => {
+                compareTables(Table.from(table.serialize()), table);
+            });
         });
     }
 });
@@ -655,4 +670,4 @@ function getStructTable() {
             ]
         }]
     });
-}
\ No newline at end of file
+}

Reply via email to