|
1 | 1 | package nextflow.parquet |
2 | 2 |
|
| 3 | +import com.jerolba.carpet.CarpetReader |
3 | 4 | import nextflow.Channel |
4 | 5 | import nextflow.plugin.Plugins |
5 | 6 | import nextflow.plugin.TestPluginDescriptorFinder |
@@ -119,4 +120,75 @@ class PluginTest extends Dsl2Spec{ |
119 | 120 | pathOutput.toFile().length() |
120 | 121 | } |
121 | 122 |
|
| 123 | + def 'should parse a parquet file in raw mode using by 1'() { |
| 124 | + given: |
| 125 | + def path = getClass().getResource('/multiple.parquet').toURI().path |
| 126 | + |
| 127 | + when: |
| 128 | + def SCRIPT = """ |
| 129 | + include {splitParquet} from 'plugin/nf-parquet' |
| 130 | + channel.fromPath("$path").splitParquet(by:1) |
| 131 | + """.toString() |
| 132 | + and: |
| 133 | + def result = new MockScriptRunner([:]).setScript(SCRIPT).execute() |
| 134 | + then: |
| 135 | + result.val == [[id: 1, name: "The 1 record"]] |
| 136 | + result.val == [[id: 2, name: "The 2 record"]] |
| 137 | + result.val == [[id: 3, name: "The 3 record"]] |
| 138 | + result.val == Channel.STOP |
| 139 | + } |
| 140 | + |
| 141 | + def 'should parse a parquet file in raw mode using by 2'(){ |
| 142 | + given: |
| 143 | + def path = getClass().getResource('/multiple.parquet').toURI().path |
| 144 | + when: |
| 145 | + def SCRIPT = """ |
| 146 | + include {splitParquet} from 'plugin/nf-parquet' |
| 147 | + channel.fromPath("$path").splitParquet(by:2) |
| 148 | + """.toString() |
| 149 | + and: |
| 150 | + def result = new MockScriptRunner([:]).setScript(SCRIPT).execute() |
| 151 | + then: |
| 152 | + result.val == [ [id:1, name:"The 1 record"], [id:2, name:"The 2 record"] ] |
| 153 | + result.val == [ [id:3, name:"The 3 record"] ] |
| 154 | + result.val == Channel.STOP |
| 155 | + |
| 156 | + } |
| 157 | + |
| 158 | + def 'should write #total records to a file using by #by '(){ |
| 159 | + when: |
| 160 | + def pathOutput = Files.createTempFile("", ".parquet") |
| 161 | + def SCRIPT = """ |
| 162 | + include {splitParquet; toParquet} from 'plugin/nf-parquet' |
| 163 | +
|
| 164 | + import nextflow.parquet.DemoRecord |
| 165 | +
|
| 166 | + channel.of(1..$total) |
| 167 | + .map( { new DemoRecord(it, "The \$it record") } ) |
| 168 | + .toParquet("$pathOutput", [record:DemoRecord, by:$by]) |
| 169 | + .view() |
| 170 | + """.toString() |
| 171 | + and: |
| 172 | + def result = new MockScriptRunner([:]).setScript(SCRIPT).execute() |
| 173 | + def values = (1..total).collect{ result.val } |
| 174 | + then: |
| 175 | + values.size() == total |
| 176 | + result.val == Channel.STOP |
| 177 | + |
| 178 | + when: |
| 179 | + final reader = new CarpetReader(pathOutput.toFile(), Map) |
| 180 | + int count = 0 |
| 181 | + for (def record : reader) { |
| 182 | + println record |
| 183 | + count++ |
| 184 | + } |
| 185 | + then: |
| 186 | + count == total |
| 187 | + |
| 188 | + where: |
| 189 | + by | total |
| 190 | + 1 | 100 |
| 191 | + 10 | 100 |
| 192 | + 100 | 100 |
| 193 | + } |
122 | 194 | } |
0 commit comments