You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/02/18 22:00:09 UTC

[GitHub] [arrow] trxcllnt commented on a change in pull request #12451: ARROW-15705: [JavaScript] Allowing appending null on children in a StructBuilder

trxcllnt commented on a change in pull request #12451:
URL: https://github.com/apache/arrow/pull/12451#discussion_r810364151



##########
File path: js/src/builder/struct.ts
##########
@@ -23,12 +23,31 @@ import { Struct, TypeMap } from '../type.js';
 
 /** @ignore */
 export class StructBuilder<T extends TypeMap = any, TNull = any> extends Builder<Struct<T>, TNull> {
-    public setValue(index: number, value: Struct<T>['TValue']) {
+    /**
+     * Write a value (or null-value sentinel) at the supplied index.
+     * If the value matches one of the null-value representations, a 1-bit is
+     * written to the null `BitmapBufferBuilder`, otherwise, a 0 is written. The
+     * value is then passed to `Builder.prototype.setValue()`.
+     * @param {number} index The index of the value to write.
+     * @param {T['TValue'] | TNull } value The value to write at the supplied index.
+     * @returns {this} The updated `Builder` instance.
+     */
+    public set(index: number, value: Struct<T>['TValue'] | TNull) {
+        this.setValid(index, this.isValid(value));
+        this.setValue(index, value);
+        return this;
+    }
+
+    public setValue(index: number, value: Struct<T>['TValue'] | TNull) {
         const children = this.children;
-        switch (Array.isArray(value) || value.constructor) {
-            case true: return this.type.children.forEach((_, i) => children[i].set(index, value[i]));
-            case Map: return this.type.children.forEach((f, i) => children[i].set(index, value.get(f.name)));
-            default: return this.type.children.forEach((f, i) => children[i].set(index, value[f.name]));
+        if (this.isValid(value) && 'constructor' in value) {
+            switch (Array.isArray(value) || value.constructor) {
+                case true: return this.type.children.forEach((_, i) => children[i].set(index, value[i]));
+                case Map: return this.type.children.forEach((f, i) => children[i].set(index, value.get(f.name)));
+                default: return this.type.children.forEach((f, i) => children[i].set(index, value[f.name]));
+            }
+        } else { // Is a null value
+            return this.type.children.forEach((_, i) => children[i].set(index, value));

Review comment:
       If the above is applied, we can revert these changes.

##########
File path: js/src/builder/struct.ts
##########
@@ -23,12 +23,31 @@ import { Struct, TypeMap } from '../type.js';
 
 /** @ignore */
 export class StructBuilder<T extends TypeMap = any, TNull = any> extends Builder<Struct<T>, TNull> {
-    public setValue(index: number, value: Struct<T>['TValue']) {
+    /**
+     * Write a value (or null-value sentinel) at the supplied index.
+     * If the value matches one of the null-value representations, a 1-bit is
+     * written to the null `BitmapBufferBuilder`, otherwise, a 0 is written. The
+     * value is then passed to `Builder.prototype.setValue()`.
+     * @param {number} index The index of the value to write.
+     * @param {T['TValue'] | TNull } value The value to write at the supplied index.
+     * @returns {this} The updated `Builder` instance.
+     */
+    public set(index: number, value: Struct<T>['TValue'] | TNull) {
+        this.setValid(index, this.isValid(value));
+        this.setValue(index, value);
+        return this;
+    }

Review comment:
       ```suggestion
       /** @inheritdoc */
       public set(index: number, value: Struct<T>['TValue'] | TNull) {
           if (this.setValid(index, this.isValid(value))) {
               this.setValue(index, value);
           } else {
             this.children.forEach((child) => child.setValid(index, false));
           }
           return this;
       }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org