What APL expression best emulates the SQL select statement, given a matrix

Viewed 68

I have CSV files with numeric data and I would like to perform analysis on this data. I am hoping that using APL will give me more flexibility than reading this into mysql and performing selects. But to start with I would like to do simple extractions like 'select * from mydata where col1 = 2020'. So far I understand I can use Compress. But for that I need to know the expression that would yield the boolean array for the left argument of compress (i.e. the APL version of 'where col1 = 2020'). Online searches did not get me anywhere in that department.

1 Answers

You are indeed right in your speculations.

"col1 = 2020" would be mydata[;1] = 2020 so the entire thing is (mydata[;1] = 2020) ⌿ mydata

My father liked to define

∇ data ← data where condition
  data ← condition⌿data
∇

so he could write things like data where data[;1] = 2020

Utilising Dyalog APL features

Dyalog APL provides some notational niceties:

  • The inline expression can be written as mydata ⌿⍨ mydata[;1] = 2020
  • The above definition of where can be written simply as where ← ⌿⍨
Related