Created
August 21, 2018 20:24
-
-
Save skokenes/587740af616e73db5a2cb7d9e3d6592c to your computer and use it in GitHub Desktop.
Loading a CSV with Qlik Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { connectSession } = require("rxq"); | |
const { concat } = require("rxjs"); | |
const { switchMap, shareReplay, take, tap } = require("rxjs/operators"); | |
const config = { | |
host: "localhost", | |
port: 19076 | |
}; | |
// Engine Session | |
const session = connectSession(config); | |
// Create and open doc | |
const doc$ = session.global$.pipe( | |
switchMap(h => | |
h | |
.ask("CreateApp", "RussianTweets.qvf") | |
.pipe(switchMap(() => h.ask("OpenDoc", "RussianTweets.qvf"))) | |
), | |
shareReplay(1) | |
); | |
// Create connection | |
const createConnection$ = doc$.pipe( | |
switchMap(h => | |
h.ask("CreateConnection", { | |
qName: "data", | |
qConnectionString: "/data", | |
qType: "folder" | |
}) | |
), | |
take(1) | |
); | |
// Create load script | |
const script = ` | |
Load * | |
FROM [lib://data/IRA_tweets_combined.csv] | |
(txt, utf8, embedded labels, delimiter is ','); | |
`; | |
const setScript$ = doc$.pipe( | |
switchMap(h => h.ask("SetScript", script)), | |
take(1) | |
); | |
let startTime; | |
// Do reload | |
const doReload$ = doc$.pipe( | |
tap(() => { | |
console.log("started reload"); | |
startTime = Date.now(); | |
}), | |
switchMap(h => h.ask("DoReload")), | |
tap(() => console.log("reloaded")), | |
tap(() => { | |
console.log(Date.now() - startTime); | |
}), | |
take(1) | |
); | |
// Do save | |
const doSave$ = doc$.pipe( | |
switchMap(h => h.ask("DoSave")), | |
tap(() => console.log("saved")), | |
take(1) | |
); | |
// Execute the chain | |
concat(createConnection$, setScript$, doReload$, doSave$).subscribe( | |
() => {}, | |
err => console.log(err) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment