Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces CLI to use Pico CLI #946

Merged
merged 6 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions docs/tutorials/Command Line Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,38 @@ project root).

Be sure to include the correct relative path to `gradlew` if you are not in the project root.

## CLI Commands
## CLI Options

To view all commands available, run the CLI with the `--help` option.
To view all available options, run the CLI with the `--help` option.

## Shell
## Non-Interactive (Single Query Execution)

To execute a single query, run:

```shell
./partiql-app/partiql-cli/shell.sh -q query.partiql
```

where `query.partiql` contains the PartiQL query to execute.

Alternatively, you may pipe input into the native command:

```shell
# Via `echo`
echo "SELECT * FROM [0, 1, 2]" | ./partiql-app/partiql-cli/build/install/partiql-cli/bin/partiql

# Via `cat`
echo ~/Desktop/query.partiql | ./partiql-app/partiql-cli/build/install/partiql-cli/bin/partiql
```

## Interactive (Shell)

To start an interactive shell, execute:

> Note that running directly with Gradle will eat arrow keys and control sequences due to the Gradle daemon.

```shell
./partiql-app/partiql-cli/shell.sh shell
./partiql-app/partiql-cli/shell.sh
```

You will see a prompt that looks as follows:
Expand Down Expand Up @@ -82,7 +102,7 @@ PartiQL> SELECT id + 4 AS name FROM _;

Press control-D to exit the REPL.

### Advanced REPL Features
### Advanced Shell Features

To view the AST of a PartiQL statement, type the statement and press enter only *once*, then type `!!` and press enter:

Expand Down Expand Up @@ -118,7 +138,7 @@ OK!

### Initial Environment

The initial environment for the REPL can be setup with a configuration file, which should be a PartiQL file with a
The initial environment for the Shell can be setup with a configuration file, which should be a PartiQL file with a
single `struct` containing the initial *global environment*.

For example, a file named `config.env` contains the following:
Expand All @@ -139,18 +159,16 @@ For example, a file named `config.env` contains the following:
```

The variables `animals` and `types` can both be bound to the execution environment for later access.
To bind the environment file to the execution environment, start the REPL with the following command:
To bind the environment file to the execution environment, start the Shell with the following command:

```shell
$ ./partiql-app/partiql-cli/shell.sh shell -e config.env
$ ./partiql-app/partiql-cli/shell.sh -e config.env
```

**Note**: Shell expansions such as `~` do not work within the value of the `args` argument.

Or, if you have extracted one of the compressed archives:

```shell
$ ./bin/partiql shell -e config.env
$ ./bin/partiql -e config.env
```

Expressions can then use the environment defined by `config.env`:
Expand Down Expand Up @@ -178,7 +196,7 @@ PartiQL> SELECT name, type, is_magic FROM animals, types WHERE type = id
>>
```

To see the current REPL environment you can use `!global_env`, for example for the file above:
To see the current Shell environment you can use `!global_env`, for example for the file above:

```shell
PartiQL> !global_env;
Expand Down Expand Up @@ -380,7 +398,7 @@ PartiQL> SELECT * FROM stores AS s
```

## Reading/Writing Files
The REPL provides the `read_file` function to stream data from a file. The files need to be placed in the folder `cli`,
The CLI provides the `read_file` function to stream data from a file. The files need to be placed in the folder `cli`,
and, if using the default file type (Ion), they must contain only a single Ion value (typically a list).

**Note**: Later on, we will introduce reading different file types, but we will first focus on the default (Ion).
Expand Down Expand Up @@ -411,7 +429,7 @@ PartiQL> SELECT city FROM read_file('data.ion') AS c, `["HI", "NY"]` AS s WHERE
>>
```

The REPL also has the capability to write files with the `write_file` function:
The CLI also has the capability to write files with the `write_file` function:

```shell
PartiQL> write_file('out.ion', SELECT * FROM _);
Expand Down Expand Up @@ -687,7 +705,7 @@ For in-depth documentation on valid DDB PartiQL queries, please reference the of
[AWS DynamoDB PartiQL Docs](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.html).

## Permissive Typing Mode
By default, the CLI/REPL runs in [LEGACY](https://github.com/partiql/partiql-lang-kotlin/blob/main/lang/src/org/partiql/lang/eval/CompileOptions.kt#L53-L62)
By default, the CLI runs in [LEGACY](https://github.com/partiql/partiql-lang-kotlin/blob/main/lang/src/org/partiql/lang/eval/CompileOptions.kt#L53-L62)
typing mode, which will give an evaluation time error in the case of data type mismatches.

```shell
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ The root folder `partiql-cli` contains a `README.md` file and 3 subfolders
### Windows

Run (double click on) `partiql.bat`. This should open a command-line
prompt and start the PartiQL CLI which displays:
prompt and start the PartiQL Shell which displays:

```shell
Welcome to the PartiQL CLI!
Welcome to the PartiQL Shell!
```

### macOS (Mac) and Unix
Expand All @@ -81,7 +81,7 @@ Welcome to the PartiQL CLI!
The folder name will have the PartiQL version as a suffix, i.e., `partiql-cli-0.1.0`.

```shell
Welcome to the PartiQL CLI!
Welcome to the PartiQL Shell!
```

### Command Line Tutorial
Expand Down
2 changes: 1 addition & 1 deletion partiql-app/partiql-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {

application {
applicationName = "partiql"
mainClass.set("org.partiql.Main")
mainClass.set("org.partiql.cli.Main")
}

distributions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@

@file:Suppress("DEPRECATION")

package org.partiql
package org.partiql.cli

import com.amazon.ion.system.IonSystemBuilder
import org.partiql.cli.pico.PartiQLCommand
import org.partiql.lang.eval.ExprValueFactory
import org.partiql.pico.CommandPartiQL
import org.partiql.pico.CommandQuery
import org.partiql.pico.CommandShell
import picocli.CommandLine
import kotlin.system.exitProcess

Expand All @@ -31,9 +29,7 @@ import kotlin.system.exitProcess
fun main(args: Array<String>) {
val ion = IonSystemBuilder.standard().build()
val valueFactory = ExprValueFactory.standard(ion)
val command = CommandLine(CommandPartiQL())
.addSubcommand(CommandQuery(valueFactory))
.addSubcommand(CommandShell(valueFactory))
val command = CommandLine(PartiQLCommand(valueFactory))
val exitCode = command.execute(*args)
exitProcess(exitCode)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
* language governing permissions and limitations under the License.
*/

package org.partiql.format
package org.partiql.cli.format

import org.partiql.format.dot.DotGraph
import org.partiql.format.dot.DotNodeId
import org.partiql.format.dot.DotNodeShape
import org.partiql.format.dot.DotNodeStmt
import org.partiql.format.dot.digraph
import org.partiql.cli.format.dot.DotGraph
import org.partiql.cli.format.dot.DotNodeId
import org.partiql.cli.format.dot.DotNodeShape
import org.partiql.cli.format.dot.DotNodeStmt
import org.partiql.cli.format.dot.digraph
import org.partiql.lang.domains.PartiqlAst
import org.partiql.lang.domains.PartiqlLogical
import org.partiql.lang.domains.PartiqlLogicalResolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* language governing permissions and limitations under the License.
*/

package org.partiql.format
package org.partiql.cli.format

import com.google.common.net.PercentEscaper
import org.partiql.pig.runtime.DomainNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* language governing permissions and limitations under the License.
*/

package org.partiql.format
package org.partiql.cli.format

import org.partiql.lang.eval.PartiQLResult

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* language governing permissions and limitations under the License.
*/

package org.partiql.format
package org.partiql.cli.format

import org.partiql.pig.runtime.DomainNode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* language governing permissions and limitations under the License.
*/

package org.partiql.format
package org.partiql.cli.format

import com.amazon.ion.system.IonTextWriterBuilder
import org.partiql.pig.runtime.DomainNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* language governing permissions and limitations under the License.
*/

package org.partiql.format
package org.partiql.cli.format

import org.partiql.lang.domains.PartiqlLogical
import org.partiql.lang.domains.PartiqlLogicalResolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* language governing permissions and limitations under the License.
*/

package org.partiql.format
package org.partiql.cli.format

import org.partiql.pig.runtime.DomainNode
import kotlin.reflect.full.memberProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* language governing permissions and limitations under the License.
*/

package org.partiql.format.dot
package org.partiql.cli.format.dot

import kotlin.properties.ObservableProperty
import kotlin.properties.ReadWriteProperty
Expand Down Expand Up @@ -105,7 +105,7 @@ sealed class DotGraph(

/**
* I couldn't figure out how to chain edges while also attaching edge attributes
* hence why these return a org.partiql.format.DotEdgeStmt and not the rhs
* hence why these return a org.partiql.cli.format.DotEdgeStmt and not the rhs
*/

/**
Expand Down Expand Up @@ -475,7 +475,7 @@ interface DotEntity {
}

/**
* Calling a org.partiql.format.DotVertex entities that can be the source or target of an edge -- i.e. node ids and subgraphs
* Calling a org.partiql.cli.format.DotVertex entities that can be the source or target of an edge -- i.e. node ids and subgraphs
* This affects indentation in Dot generating.
*/
interface DotVertex {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* language governing permissions and limitations under the License.
*/

package org.partiql.functions
package org.partiql.cli.functions

import com.amazon.ion.system.IonReaderBuilder
import org.apache.commons.csv.CSVFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* language governing permissions and limitations under the License.
*/

package org.partiql.functions
package org.partiql.cli.functions

import com.amazon.ion.IonSystem
import com.amazon.ion.system.IonSystemBuilder
Expand Down
Loading