Here's how I pull data from a DB, stash it in column based binary J
files, and map them using jmf.  After that I can just use the inverted
table mechanisms explained so nicely on the J wiki.

I would assume you can do similar with your CSV problem.


require 'dates dd files jmf printf'

DSN =: 'dsn=something;uid=user;pwd=password'

STMT =: 'SELECT date_field, float_field, int_field FROM a_table'

i2b =: 2 & (3!:4)
writeints =: (fappend~ i2b)~

f2b =: 2 & (3!:5)
writefloats =: (fappend~ f2b)~

getdata =: 4 : 0
        stmt =. x
        dsn =. y
        ch =. ddcon dsn
        'Executing SQL:\n%s' printf <stmt
        sh =. stmt ddsel ch
        ddbind sh
        total =. 0
        while. 0 <: ddfetch sh do.
                rcnt =. 0 { ddrow sh            NB. ddrow appears to return an 
array of one element!
                'Saving %d rows.' printf <rcnt
                (tsrep dts_jdd_ rcnt {. dddata sh,1) writefloats 'DATE.ijn'
                (rcnt {. , dddata sh,2) writeints 'INT.ijn'
                (rcnt {. , dddata sh,3) writefloats 'FLOAT.ijn'
                total =. total + rcnt
        end.
        ddend sh
        dddis ch
        'Saved a total of %d rows.' printf <total
        total
)

mapdata =: 3 : 0
        JFL map_jmf_ 'DATE';'DATE.ijn'
        JINT map_jmf_ 'INT';'INT.ijn'
        JFL map_jmf_ 'FLOAT';'FLOAT.ijn'
)

STMT getdata DSN
mapdata ''

+/ INT

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to