-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the WriteFile CLI Command to properly output query results to a file (See #606) and update the README
- Loading branch information
1 parent
b633476
commit ba62b66
Showing
4 changed files
with
234 additions
and
31 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.partiql.cli | ||
|
||
import com.amazon.ion.IonSystem | ||
import com.amazon.ion.system.IonSystemBuilder | ||
import org.junit.Assert | ||
import org.partiql.lang.CompilerPipeline | ||
import org.partiql.lang.eval.Bindings | ||
import org.partiql.lang.eval.ExprValue | ||
import org.partiql.lang.eval.ExprValueFactory | ||
import java.io.ByteArrayOutputStream | ||
import java.io.OutputStream | ||
|
||
/** | ||
* Initializes a CLI and runs the passed-in query | ||
*/ | ||
fun makeCliAndGetResult( | ||
query: String, | ||
input: String? = null, | ||
bindings: Bindings<ExprValue> = Bindings.empty(), | ||
outputFormat: OutputFormat = OutputFormat.ION_TEXT, | ||
output: OutputStream = ByteArrayOutputStream(), | ||
ion: IonSystem = IonSystemBuilder.standard().build(), | ||
compilerPipeline: CompilerPipeline = CompilerPipeline.standard(ion), | ||
valueFactory: ExprValueFactory = ExprValueFactory.standard(ion) | ||
): String { | ||
val cli = Cli( | ||
valueFactory, | ||
input?.byteInputStream(Charsets.UTF_8) ?: EmptyInputStream(), | ||
output, | ||
outputFormat, | ||
compilerPipeline, | ||
bindings, | ||
query | ||
) | ||
cli.run() | ||
return output.toString() | ||
} | ||
|
||
/** | ||
* An assertion helper | ||
*/ | ||
fun assertAsIon(expected: String, actual: String) { | ||
val ion = IonSystemBuilder.standard().build() | ||
assertAsIon(ion, expected, actual) | ||
} | ||
|
||
/** | ||
* An assertion helper | ||
*/ | ||
fun assertAsIon(ion: IonSystem, expected: String, actual: String) = | ||
Assert.assertEquals(ion.loader.load(expected), ion.loader.load(actual)) |
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