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

[cli] remove wildcard imports #483

Merged
merged 3 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
70 changes: 56 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ build
out/


# Created by https://www.gitignore.io/api/vim,git,java,emacs,kotlin,eclipse,intellij+all
# Edit at https://www.gitignore.io/?templates=vim,git,java,emacs,kotlin,eclipse,intellij+all
# Created by https://www.toptal.com/developers/gitignore/api/vim,git,java,emacs,kotlin,eclipse,intellij+all,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=vim,git,java,emacs,kotlin,eclipse,intellij+all,macos

### Eclipse ###
.metadata
Expand All @@ -24,6 +24,16 @@ local.properties
.loadpath
.recommenders

### Eclipse Patch ###
# Eclipse Core
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Annotation Processing
.apt_generated

# External tool builders
.externalToolBuilders/

Expand Down Expand Up @@ -62,22 +72,19 @@ local.properties

# Annotation Processing
.apt_generated/
.apt_generated_test/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

### Eclipse Patch ###
# Eclipse Core
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Annotation Processing
.apt_generated
# Uncomment this line if you wish to ignore the project description file.
# Typically, this file would be tracked if it contains build/dependency configurations:
#.project

### Eclipse Patch ###
# Spring Boot Tooling
.sts4-cache/

### Emacs ###
Expand Down Expand Up @@ -147,7 +154,7 @@ flycheck_*.el
*_REMOTE_*.txt

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
Expand All @@ -157,6 +164,9 @@ flycheck_*.el
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

Expand All @@ -177,6 +187,9 @@ flycheck_*.el
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
Expand Down Expand Up @@ -270,9 +283,39 @@ hs_err_pid*

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
Expand All @@ -289,5 +332,4 @@ tags
# Persistent undo
[._]*.un~

# End of https://www.gitignore.io/api/vim,git,java,emacs,kotlin,eclipse,intellij+all

# End of https://www.toptal.com/developers/gitignore/api/vim,git,java,emacs,kotlin,eclipse,intellij+all,macos
6 changes: 0 additions & 6 deletions cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
id 'application'
}


application {
mainClassName = "org.partiql.cli.Main"
applicationName = 'partiql' // startup script name
Expand All @@ -19,16 +18,11 @@ distributions {
}
}





(tasks.findByName("distTar") as Tar).compression = Compression.GZIP

// Allows the CLI to receive input from the keyboard when invoked using `./gradlew :cli:run`
tasks['run'].standardInput = System.in


dependencies {
implementation project(":lang")
implementation 'net.sf.jopt-simple:jopt-simple:[5.0,6.0)'
Expand Down
30 changes: 19 additions & 11 deletions cli/src/org/partiql/cli/Cli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@

package org.partiql.cli

import com.amazon.ion.*
import com.amazon.ion.system.*
import java.io.*
import org.partiql.cli.OutputFormat.*
import org.partiql.lang.*
import org.partiql.lang.eval.*
import com.amazon.ion.IonWriter
import com.amazon.ion.system.IonReaderBuilder
import com.amazon.ion.system.IonTextWriterBuilder
import org.partiql.lang.CompilerPipeline
import org.partiql.lang.eval.Bindings
import org.partiql.lang.eval.EvaluationSession
import org.partiql.lang.eval.ExprValue
import org.partiql.lang.eval.ExprValueFactory
import org.partiql.lang.eval.ExprValueType
import org.partiql.lang.eval.delegate
import org.partiql.lang.util.ConfigurableExprValueFormatter
import java.io.InputStream
import java.io.OutputStream
import java.io.OutputStreamWriter

/**
* TODO builder, kdoc
Expand All @@ -34,7 +41,8 @@ internal class Cli(private val valueFactory: ExprValueFactory,
private val query: String) : PartiQLCommand {

companion object {
val ionTextWriterBuilder: IonTextWriterBuilder = IonTextWriterBuilder.standard().withWriteTopLevelValuesOnNewLines(true)
val ionTextWriterBuilder: IonTextWriterBuilder = IonTextWriterBuilder.standard()
.withWriteTopLevelValuesOnNewLines(true)
}

override fun run() {
Expand All @@ -49,13 +57,13 @@ internal class Cli(private val valueFactory: ExprValueFactory,
val result = compilerPipeline.compile(query).eval(EvaluationSession.build { globals(bindings) })

when (format) {
ION_TEXT -> ionTextWriterBuilder.build(output).use {
OutputFormat.ION_TEXT -> ionTextWriterBuilder.build(output).use {
printIon(it, result)
output.write(System.lineSeparator().toByteArray(Charsets.UTF_8))
}
ION_BINARY -> valueFactory.ion.newBinaryWriter(output).use { printIon(it, result) }
PARTIQL -> OutputStreamWriter(output).use { it.write(result.toString()) }
PARTIQL_PRETTY -> OutputStreamWriter(output).use {
OutputFormat.ION_BINARY -> valueFactory.ion.newBinaryWriter(output).use { printIon(it, result) }
OutputFormat.PARTIQL -> OutputStreamWriter(output).use { it.write(result.toString()) }
OutputFormat.PARTIQL_PRETTY -> OutputStreamWriter(output).use {
ConfigurableExprValueFormatter.pretty.formatTo(result, it)
}
}
Expand Down
86 changes: 47 additions & 39 deletions cli/src/org/partiql/cli/Repl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@

package org.partiql.cli

import com.amazon.ion.system.*
import com.amazon.ion.system.IonTextWriterBuilder
import com.amazon.ionelement.api.toIonValue
import org.partiql.cli.ReplState.*
import org.partiql.lang.*
import org.partiql.lang.eval.*
import org.partiql.lang.syntax.*
import org.partiql.lang.util.*
import java.io.*
import org.partiql.lang.CompilerPipeline
import org.partiql.lang.eval.BindingCase
import org.partiql.lang.eval.BindingName
import org.partiql.lang.eval.Bindings
import org.partiql.lang.eval.EvaluationSession
import org.partiql.lang.eval.ExprValue
import org.partiql.lang.eval.ExprValueFactory
import org.partiql.lang.eval.MapBindings
import org.partiql.lang.eval.StructOrdering
import org.partiql.lang.eval.delegate
import org.partiql.lang.syntax.Parser
import org.partiql.lang.util.ConfigurableExprValueFormatter
import org.partiql.lang.util.ExprValueFormatter
import java.io.InputStream
import java.io.OutputStream
import java.io.OutputStreamWriter
import java.io.PrintWriter
import java.util.Properties
import java.util.concurrent.*
import java.util.concurrent.TimeUnit

internal const val PROMPT_1 = "PartiQL> "
internal const val PROMPT_2 = " | "
Expand Down Expand Up @@ -61,9 +72,6 @@ private enum class ReplState {
}

private class GlobalBinding(private val valueFactory: ExprValueFactory) {



private val knownNames = mutableSetOf<String>()
var bindings = Bindings.empty<ExprValue>()
private set
Expand Down Expand Up @@ -182,7 +190,7 @@ internal class Repl(private val valueFactory: ExprValueFactory,
// Repl running state
private val buffer = StringBuilder()
private var globals = GlobalBinding(valueFactory).add(initialGlobal)
private var state = INIT
private var state = ReplState.INIT
private var previousResult = valueFactory.nullValue
private var line: String? = null

Expand Down Expand Up @@ -244,10 +252,10 @@ internal class Repl(private val valueFactory: ExprValueFactory,
}

return if (line == null) {
FINAL
ReplState.FINAL
}
else {
READY
ReplState.READY
}
}

Expand All @@ -274,58 +282,58 @@ internal class Repl(private val valueFactory: ExprValueFactory,
}

override fun run() {
while (state != FINAL) {
while (state != ReplState.FINAL) {
state = when (state) {
INIT -> {
ReplState.INIT -> {
printWelcomeMessage()
printVersionNumber()
READY
ReplState.READY
}

READY -> {
ReplState.READY -> {
line = readLine()
when {
line == null -> FINAL
arrayOf("!!", "").any { it == line } -> EXECUTE_PARTIQL
line!!.startsWith("!") -> READ_REPL_COMMAND
line!!.endsWith(";") -> LAST_PARTIQL_LINE
else -> READ_PARTIQL
line == null -> ReplState.FINAL
arrayOf("!!", "").any { it == line } -> ReplState.EXECUTE_PARTIQL
line!!.startsWith("!") -> ReplState.READ_REPL_COMMAND
line!!.endsWith(";") -> ReplState.LAST_PARTIQL_LINE
else -> ReplState.READ_PARTIQL
}
}

READ_PARTIQL -> {
ReplState.READ_PARTIQL -> {
buffer.appendln(line)
line = readLine()
when {
line == null -> FINAL
line == "" -> EXECUTE_PARTIQL
line!!.endsWith(";") -> LAST_PARTIQL_LINE
line == "!!" -> PARSE_PARTIQL_WITH_FILTER
else -> READ_PARTIQL
line == null -> ReplState.FINAL
line == "" -> ReplState.EXECUTE_PARTIQL
line!!.endsWith(";") -> ReplState.LAST_PARTIQL_LINE
line == "!!" -> ReplState.PARSE_PARTIQL_WITH_FILTER
else -> ReplState.READ_PARTIQL
}
}

LAST_PARTIQL_LINE -> {
ReplState.LAST_PARTIQL_LINE -> {
buffer.appendln(line)
EXECUTE_PARTIQL
ReplState.EXECUTE_PARTIQL
}

READ_REPL_COMMAND -> {
ReplState.READ_REPL_COMMAND -> {
buffer.appendln(line)
line = readLine()
when (line) {
null -> FINAL
"" -> EXECUTE_REPL_COMMAND
else -> READ_REPL_COMMAND
null -> ReplState.FINAL
"" -> ReplState.EXECUTE_REPL_COMMAND
else -> ReplState.READ_REPL_COMMAND
}
}

EXECUTE_PARTIQL -> executePartiQL()
PARSE_PARTIQL_WITH_FILTER -> parsePartiQLWithFilters()
EXECUTE_REPL_COMMAND -> executeReplCommand()
ReplState.EXECUTE_PARTIQL -> executePartiQL()
ReplState.PARSE_PARTIQL_WITH_FILTER -> parsePartiQLWithFilters()
ReplState.EXECUTE_REPL_COMMAND -> executeReplCommand()

// shouldn't really happen
FINAL -> FINAL
ReplState.FINAL -> ReplState.FINAL
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions cli/src/org/partiql/cli/Runnable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

package org.partiql.cli

import com.amazon.ion.*
import org.partiql.lang.eval.*
import com.amazon.ion.IonWriter
import org.partiql.lang.eval.ExprValue
import org.partiql.lang.eval.rangeOver

internal abstract class SqlCommand {
abstract fun run()


protected fun writeResult(result: ExprValue, writer: IonWriter): Int {
var itemCount = 0
result.rangeOver().forEach {
Expand Down
6 changes: 4 additions & 2 deletions cli/src/org/partiql/cli/functions/BaseFunction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

package org.partiql.cli.functions

import com.amazon.ion.*
import org.partiql.lang.eval.*
import com.amazon.ion.IonStruct
import org.partiql.lang.eval.ExprFunction
import org.partiql.lang.eval.ExprValue
import org.partiql.lang.eval.ExprValueFactory

internal abstract class BaseFunction(val valueFactory: ExprValueFactory) : ExprFunction {
protected fun optionsStruct(requiredArity: Int,
Expand Down
Loading