I'am working on an ETL script that reads data from an DB, manipulates it using Java and finally writes it to a CSV file. My script looks like this:
<query connection-id="db">
SELECT COLUMN_A AS A, COLUMN_B AS B
FROM DATABASE_TABLE
<script connection-id="java">
System.setProperty("a",String.valueOf(get("A")));
System.setProperty("b",String.valueOf(get("B")));
</script>
<script connection-id="csv_out">
$a,$b
</script>
</query>
The scripts is working in a way that I get one row written to the CSV file for each row in the query result. But what I need is a way to create more or less rows than the query result has delivered. Therefore I want a conditional output to the CSV file, based on values set in the Java part:
<script connection-id="java">
System.setProperty("a",String.valueOf(get("A")));
System.setProperty("b",String.valueOf(get("B")));
</script>
// only create line when 'a' has specific value, e.g. '1'
<script connection-id="csv_out" if="$a == 1">
$a,$b
</script>
This approach does not work. It writes nothing to the CSV, even if I set the value of 'a' explicitely to 1. So what is the right way to do conditional script execution in Scriptella? Or is there an even better solution?
Got it. You just have to use the name of the varibale, without the '$' symbol.
For String values you have to use quotes around the comparison String.