(String path)
| 247 | } |
| 248 | |
| 249 | public void save(String path) { |
| 250 | URI outputUri = null; |
| 251 | outputUri = FileSystemUtil.resolveURIAgainstWorkingDirectory( |
| 252 | path, |
| 253 | this.configuration, |
| 254 | ExceptionMetadata.EMPTY_METADATA |
| 255 | ); |
| 256 | String method = this.serializationParameters.getMethod(); |
| 257 | // DataFrame mode: delegate to Spark's DataFrameWriter, using the serialization method |
| 258 | // as the Spark output format (json/csv/parquet/other). |
| 259 | if (this.dataFrameWriter != null) { |
| 260 | Logger logger = LogManager.getLogger(SequenceWriter.class); |
| 261 | for (Map.Entry<String, String> option : this.serializationParameters.getSparkOptions().entrySet()) { |
| 262 | logger.info("Writing with option " + option.getKey() + " : " + option.getValue()); |
| 263 | } |
| 264 | logger.info("Writing to format " + method); |
| 265 | DataFrameWriter<Row> writerWithOptions = applyStoredSparkOptions(this.dataFrameWriter); |
| 266 | String target = FileSystemUtil.convertURIToStringForSpark(outputUri); |
| 267 | if (method.equalsIgnoreCase("json")) { |
| 268 | writerWithOptions.json(target); |
| 269 | } else if (method.equalsIgnoreCase("csv")) { |
| 270 | writerWithOptions.csv(target); |
| 271 | } else if (method.equalsIgnoreCase("parquet")) { |
| 272 | writerWithOptions.parquet(target); |
| 273 | } else { |
| 274 | writerWithOptions.format(method).save(target); |
| 275 | } |
| 276 | return; |
| 277 | } |
| 278 | // RDD mode: serialize each item via Serializer and save as text. |
| 279 | if ( |
| 280 | !(method.equals("json") |
| 281 | || method.equals("tyson") |
| 282 | || method.equals("xml-json-hybrid") |
| 283 | || method.equals("yaml") |
| 284 | || method.equals("delta")) |
| 285 | ) { |
| 286 | throw new CliException( |
| 287 | "Rumble cannot output another format than json or tyson or xml-json-hybrid or yaml if the query does not output a structured collection. You can create a structured collection from a sequence of objects by calling the function annotate(<your query here> , <a schema here>)." |
| 288 | ); |
| 289 | } |
| 290 | if (FileSystemUtil.exists(outputUri, this.configuration, ExceptionMetadata.EMPTY_METADATA)) { |
| 291 | switch (this.mode) { |
| 292 | case Overwrite: |
| 293 | FileSystemUtil.delete(outputUri, this.configuration, ExceptionMetadata.EMPTY_METADATA); |
| 294 | break; |
| 295 | case Ignore: |
| 296 | return; |
| 297 | case ErrorIfExists: |
| 298 | throw new CliException( |
| 299 | "Output path " |
| 300 | + outputUri |
| 301 | + " already exists. Please change the mode or use --overwrite yes to overwrite." |
| 302 | ); |
| 303 | case Append: |
| 304 | throw new CliException( |
| 305 | "Append currently not supported when the output is not a DataFrame." |
| 306 | ); |
no test coverage detected