[jira] [Commented] (ARROW-2159) [JS] Support custom predicates

2018-02-19 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/ARROW-2159?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16369436#comment-16369436
 ] 

ASF GitHub Bot commented on ARROW-2159:
---

TheNeuralBit closed pull request #1616: ARROW-2159: [JS] Support custom 
predicates
URL: https://github.com/apache/arrow/pull/1616
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/js/src/Arrow.externs.js b/js/src/Arrow.externs.js
index 21dca8be8..de1e65392 100644
--- a/js/src/Arrow.externs.js
+++ b/js/src/Arrow.externs.js
@@ -70,6 +70,7 @@ CountByResult.prototype.asJSON;
 
 var col = function () {};
 var lit = function () {};
+var custom = function () {};
 
 var Value = function() {};
 /** @type {?} */
@@ -738,4 +739,4 @@ VectorVisitor.prototype.visitInterval;
 /** @type {?} */
 VectorVisitor.prototype.visitFixedSizeList;
 /** @type {?} */
-VectorVisitor.prototype.visitMap;
\ No newline at end of file
+VectorVisitor.prototype.visitMap;
diff --git a/js/src/Arrow.ts b/js/src/Arrow.ts
index df37a8fb0..4a0a2ac6d 100644
--- a/js/src/Arrow.ts
+++ b/js/src/Arrow.ts
@@ -168,6 +168,7 @@ export namespace view {
 export namespace predicate {
 export import col = predicate_.col;
 export import lit = predicate_.lit;
+export import custom = predicate_.custom;
 
 export import Or = predicate_.Or;
 export import Col = predicate_.Col;
diff --git a/js/src/predicate.ts b/js/src/predicate.ts
index 981ffb166..b177b4fa7 100644
--- a/js/src/predicate.ts
+++ b/js/src/predicate.ts
@@ -222,5 +222,19 @@ export class GTeq extends ComparisonPredicate {
 }
 }
 
+export class CustomPredicate extends Predicate {
+constructor(private next: PredicateFunc, private bind_: (batch: 
RecordBatch) => void) {
+super();
+}
+
+bind(batch: RecordBatch) {
+this.bind_(batch);
+return this.next;
+}
+}
+
 export function lit(v: any): Value { return new Literal(v); }
 export function col(n: string): Col { return new Col(n); }
+export function custom(next: PredicateFunc, bind: (batch: RecordBatch) => 
void) {
+return new CustomPredicate(next, bind);
+}
diff --git a/js/test/unit/table-tests.ts b/js/test/unit/table-tests.ts
index ffcc8f477..8a433815d 100644
--- a/js/test/unit/table-tests.ts
+++ b/js/test/unit/table-tests.ts
@@ -15,11 +15,11 @@
 // specific language governing permissions and limitations
 // under the License.
 
-import Arrow from '../Arrow';
+import Arrow, { RecordBatch } from '../Arrow';
 
 const { predicate, Table } = Arrow;
 
-const { col, lit } = predicate;
+const { col, lit, custom } = predicate;
 
 const F32 = 0, I32 = 1, DICT = 2;
 const test_data = [
@@ -323,6 +323,7 @@ describe(`Table`, () => {
 expect(table.getColumnIndex('f32')).toEqual(F32);
 expect(table.getColumnIndex('dictionary')).toEqual(DICT);
 });
+let get_i32: (idx: number) => number, get_f32: (idx: number) => 
number;
 const filter_tests = [
 {
 name: `filter on f32 >= 0`,
@@ -364,6 +365,15 @@ describe(`Table`, () => {
 name: `filter on f32 <= i32`,
 filtered: table.filter(col('f32').lteq(col('i32'))),
 expected: values.filter((row) => row[F32] <= row[I32])
+}, {
+name: `filter on f32*i32 > 0 (custom predicate)`,
+filtered: table.filter(custom(
+(idx: number) => (get_f32(idx) * get_i32(idx) > 0),
+(batch: RecordBatch) => {
+get_f32 = col('f32').bind(batch);
+get_i32 = col('i32').bind(batch);
+})),
+expected: values.filter((row) => (row[F32] as number) * 
(row[I32] as number) > 0)
 }
 ];
 for (let this_test of filter_tests) {


 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [JS] Support custom predicates
> --
>
> Key: ARROW-2159
> URL: https://issues.apache.org/jira/browse/ARROW-2159
> Project: Apache Arrow
>  Issue Type: New Feature
>  Components: JavaScript
>Reporter: Brian Hulette
>Assignee: Brian Hulette
>Priority: Major
>  Labels: pull-request-available
> Fix For: JS-0.3.0
>
>
> Right now the 

[jira] [Commented] (ARROW-2159) [JS] Support custom predicates

2018-02-15 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/ARROW-2159?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16366329#comment-16366329
 ] 

ASF GitHub Bot commented on ARROW-2159:
---

TheNeuralBit opened a new pull request #1616: ARROW-2159: [JS] Support custom 
predicates
URL: https://github.com/apache/arrow/pull/1616
 
 
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [JS] Support custom predicates
> --
>
> Key: ARROW-2159
> URL: https://issues.apache.org/jira/browse/ARROW-2159
> Project: Apache Arrow
>  Issue Type: New Feature
>  Components: JavaScript
>Reporter: Brian Hulette
>Assignee: Brian Hulette
>Priority: Major
>  Labels: pull-request-available
>
> Right now the `DataFrame` interface only supports a pretty basic set of 
> operations, which could be limiting to users. We should add the ability for 
> the user to define their own predicates using callback functions.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)