You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "Anders Rune Jensen (Jira)" <ji...@apache.org> on 2020/04/18 22:11:00 UTC

[jira] [Comment Edited] (ARROW-7738) [JS] Implement list contains predicate

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

Anders Rune Jensen edited comment on ARROW-7738 at 4/18/20, 10:10 PM:
----------------------------------------------------------------------

For future travelers this can be done using something like:

 
{code:java}
    const link = '%TbiUknx1XfDdxccudfDds54hfzVNCjh2N99KXtLuyVc=.sha256'
    const uLink = new TextEncoder("utf-8").encode(link);
    
    var q2 = Array.from(
      all.filter(
        arrow.predicate.custom(
          (idx) => {
            var l = get_links(idx)
            if (l.length > 0) {
              for (var o = 0; o < l.valueOffsets.length - 1; ++o) {
                if (l.valueOffsets[o+1] - l.valueOffsets[o] != uLink.length) continue                var s = l.values.slice(l.valueOffsets[o], l.valueOffsets[o+1])                var found = true
                for (var i = 0; i < s.length; ++i) {
                  if (s[i] != uLink[i]) {
                    found = false
                    break
                  }
                }                if (found) return true
              }
              return false
            } else
              return false
          },
          (batch) => {
            get_links = arrow.predicate.col('links').bind(batch)
          })
      )
    )
{code}


was (Author: arj):
For future travelers this can be done using something like:

 
{code:java}
    const link = '%TbiUknx1XfDdxccudfDds54hfzVNCjh2N99KXtLuyVc=.sha256'
    const uLink = new TextEncoder("utf-8").encode(link);
    
    var q2 = Array.from(
      all.filter(
        arrow.predicate.custom(
          (idx) => {
            var l = get_links(idx)
            if (l.length > 0) {
              var s = l.values.slice(l.valueOffsets[0], l.valueOffsets[l.valueOffsets.length-1])
              var findIndex = 0
              for (var i = 0; i < s.length; ++i) {
                if (s[i] == uLink[findIndex])
                {
                  if (++findIndex == uLink.length)
                    return true
                } else
                  findIndex = 0
              }
              return false
            } else
              return false
          },
          (batch) => {
            get_links = arrow.predicate.col('links').bind(batch)
          })
      )
    )
{code}

> [JS] Implement list contains predicate
> --------------------------------------
>
>                 Key: ARROW-7738
>                 URL: https://issues.apache.org/jira/browse/ARROW-7738
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: JavaScript
>    Affects Versions: 0.15.1
>            Reporter: Anders Rune Jensen
>            Priority: Minor
>
> As far as I can see there is no way to check if a list contains a specific element.
> My code is as follows:
>  
> {code:java}
> var listChild = new arrow.Field('list[Utf8]', new arrow.Utf8())
> var all = arrow.Table.new([
>  arrow.DateVector.from(dates),
>  arrow.Int32Vector.from(flumeseqs),
>  arrow.Utf8Vector.from(keys),
>  arrow.Vector.from({ values: authors, type: new arrow.Dictionary(new arrow.Utf8(), new arrow.Int32()) }),
>  arrow.Int32Vector.from(sequences),
>  arrow.Vector.from({ values: types, type: new arrow.Dictionary(new arrow.Utf8(), new arrow.Int32()) }),
>  arrow.Vector.from({ values: links, type: new arrow.List(listChild) }),
>  ], ["date", "flumeseq", "key", "author", "sequence", "type", "links"])
> {code}
> And I want to get all the items that has a specific element in the links section.
> So something like:
>  
> {code:java}
> var q2 = Array.from(
> all.filter(
>  arrow.predicate.col('links').contains('%GcvjVk+NLsjOB5Vd+vceGXEOeYmHoRA6lgXVJzPuMxw=.sha256')))
> {code}
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)