diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 07c293124c61..70c3e253982e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,6 +57,16 @@ jobs: with: job-id: jdk${{ matrix.jdk }} arguments: --scan --no-parallel --no-daemon build javadoc + - name: 'sqlline and sqllsh' + shell: cmd + run: | + call sqlline.bat -e '!quit' + echo. + echo Sqlline example/csv + call example/csv/sqlline.bat --verbose -u jdbc:calcite:model=example/csv/src/test/resources/model.json -n admin -p admin -f example/csv/src/test/resources/smoke_test.sql + echo. + echo sqlsh + call sqlsh.bat -o headers "select count(*) commits, author from (select substring(author, 1, position(' <' in author)-1) author from git_commits) group by author order by count(*) desc, author limit 20" linux-avatica: if: github.event.action != 'labeled' @@ -109,6 +119,15 @@ jobs: with: job-id: jdk15 arguments: --scan --no-parallel --no-daemon build javadoc + - name: 'sqlline and sqllsh' + run: | + ./sqlline -e '!quit' + echo + echo Sqlline example/csv + ./example/csv/sqlline --verbose -u jdbc:calcite:model=example/csv/src/test/resources/model.json -n admin -p admin -f example/csv/src/test/resources/smoke_test.sql + echo + echo sqlsh + ./sqlsh -o headers "select count(*) commits, author from (select substring(author, 1, position(' <' in author)-1) author from git_commits) group by author order by count(*) desc, author limit 20" errorprone: if: github.event.action != 'labeled' diff --git a/.ratignore b/.ratignore index 7ab280750567..b6af2260745a 100644 --- a/.ratignore +++ b/.ratignore @@ -13,6 +13,7 @@ **/data.txt **/data2.txt .idea/vcs.xml +example/csv/src/test/resources/smoke_test.sql # TODO: remove when pom.xml files are removed src/main/config/licenses diff --git a/build.gradle.kts b/build.gradle.kts index 284504300d65..9dd6b0c6f134 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,6 +30,9 @@ import org.apache.calcite.buildtools.buildext.dsl.ParenthesisBalancer import org.gradle.api.tasks.testing.logging.TestExceptionFormat plugins { + // java-base is needed for platform(...) resolution, + // see https://github.com/gradle/gradle/issues/14822 + `java-base` publishing // Verification checkstyle @@ -175,6 +178,12 @@ val dataSetsForSqlline = listOf( val sqllineClasspath by configurations.creating { isCanBeConsumed = false + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.CLASSES_AND_RESOURCES)) + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, JavaVersion.current().majorVersion.toInt()) + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL)) + } } dependencies { @@ -196,7 +205,12 @@ val buildSqllineClasspath by tasks.registering(Jar::class) { manifest { attributes( "Main-Class" to "sqlline.SqlLine", - "Class-Path" to provider { sqllineClasspath.joinToString(" ") { it.absolutePath } } + "Class-Path" to provider { + // Class-Path is a list of URLs + sqllineClasspath.joinToString(" ") { + it.toURI().toURL().toString() + } + } ) } } diff --git a/example/csv/build.gradle.kts b/example/csv/build.gradle.kts index ca5ea27c7ab6..b54124b22f4e 100644 --- a/example/csv/build.gradle.kts +++ b/example/csv/build.gradle.kts @@ -44,7 +44,12 @@ val buildSqllineClasspath by tasks.registering(Jar::class) { manifest { attributes( "Main-Class" to "sqlline.SqlLine", - "Class-Path" to provider { sqllineClasspath.joinToString(" ") { it.absolutePath } } + "Class-Path" to provider { + // Class-Path is a list of URLs + sqllineClasspath.joinToString(" ") { + it.toURI().toURL().toString() + } + } ) } } diff --git a/example/csv/sqlline b/example/csv/sqlline index e2f73b0852c9..4248fa8373ab 100755 --- a/example/csv/sqlline +++ b/example/csv/sqlline @@ -27,11 +27,17 @@ case $(uname -s) in (*) cygwin=;; esac -# Build classpath on first call. (To update it run ../gradlew buildSqllineClasspath) -cd $(dirname $0) +# readlink in macOS resolves only links, and it returns empty results if the path points to a file +root=$0 +if [[ -L "$root" ]]; then + root=$(readlink "$root") +fi +root=$(cd "$(dirname "$root")"; pwd) + +CP=$root/build/libs/sqllineClasspath.jar -if [ ! -f build/libs/sqllineClasspath.jar ]; then - ../../gradlew buildSqllineClasspath +if [ "x$CACHE_SQLLINE_CLASSPATH" != "xY" ] || [ ! -f "$CP" ]; then + $root/../../gradlew --console plain -q :example:csv:buildSqllineClasspath fi VM_OPTS= @@ -40,6 +46,6 @@ if [ "$cygwin" ]; then VM_OPTS=-Djline.terminal=jline.UnixTerminal fi -exec java -Xmx1g $VM_OPTS -jar build/libs/sqllineClasspath.jar "$@" +export JAVA_OPTS=-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl -# End sqlline +exec java -Xmx1g $VM_OPTS $JAVA_OPTS -jar "$root/build/libs/sqllineClasspath.jar" "$@" diff --git a/example/csv/sqlline.bat b/example/csv/sqlline.bat index d5e893725c6f..b29b6f33666d 100644 --- a/example/csv/sqlline.bat +++ b/example/csv/sqlline.bat @@ -19,12 +19,19 @@ :: sqlline.bat - Windows script to launch SQL shell :: Example: :: > sqlline.bat -:: sqlline> !connect jdbc:calcite:model=target/test-classes/model.json admin admin +:: sqlline> !connect jdbc:calcite:model=src\test\resources\model.json admin admin :: sqlline> !tables -:: Copy dependency jars on first call. To update it run ./gradlew buildSqllineClasspath -if not exist build\libs\sqllineClasspath.jar (call ../../gradlew buildSqllineClasspath) +:: The script updates the classpath on each execution, +:: You might add CACHE_SQLLINE_CLASSPATH environment variable to cache it +:: To build classpath jar manually use gradlew buildSqllineClasspath +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set CP=%DIRNAME%\build\libs\sqllineClasspath.jar -java -Xmx1g -jar build\libs\sqllineClasspath.jar sqlline.SqlLine %* +if not defined CACHE_SQLLINE_CLASSPATH ( + if exist "%CP%" del "%CP%" +) +if not exist "%CP%" (call "%DIRNAME%\..\..\gradlew" --console plain -q :example:csv:buildSqllineClasspath) -:: End sqlline.bat +java -Xmx1g -jar "%CP%" %* diff --git a/example/csv/src/test/resources/smoke_test.sql b/example/csv/src/test/resources/smoke_test.sql new file mode 100644 index 000000000000..bf643074024a --- /dev/null +++ b/example/csv/src/test/resources/smoke_test.sql @@ -0,0 +1,3 @@ +!tables + +select 2 + 2 * 2 as "2+2*2"; diff --git a/sqlline b/sqlline index 3f99480b810c..2da73e43c166 100755 --- a/sqlline +++ b/sqlline @@ -20,21 +20,27 @@ # $ ./sqlline # sqlline> !connect jdbc:calcite: admin admin +# The script updates the classpath on each execution, +# You might use CACHE_SQLLINE_CLASSPATH=Y environment variable to cache it +# To build classpath jar manually use ./gradlew buildSqllineClasspath + # Deduce whether we are running cygwin case $(uname -s) in (CYGWIN*) cygwin=true;; (*) cygwin=;; esac -# Build classpath on first call. To update it run ./gradlew buildSqllineClasspath -root=$(cd "$(dirname "$(readlink $0)")"; pwd) +# readlink in macOS resolves only links, and it returns empty results if the path points to a file +root=$0 +if [[ -L "$root" ]]; then + root=$(readlink "$root") +fi +root=$(cd "$(dirname "$root")"; pwd) CP=$root/build/libs/sqllineClasspath.jar -if [ ! -f $CP ]; then - ( - cd $root - ./gradlew :buildSqllineClasspath - ) + +if [ "x$CACHE_SQLLINE_CLASSPATH" != "xY" ] || [ ! -f "$CP" ]; then + $root/gradlew --console plain -q :buildSqllineClasspath fi VM_OPTS= @@ -45,6 +51,4 @@ fi export JAVA_OPTS=-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl -exec java -Xmx1g $VM_OPTS $JAVA_OPTS -jar build/libs/sqllineClasspath.jar "$@" - -# End sqlline +exec java -Xmx1g $VM_OPTS $JAVA_OPTS -jar "$root/build/libs/sqllineClasspath.jar" "$@" diff --git a/sqlline.bat b/sqlline.bat index 3556c2a5d597..d98fbd62a4f2 100644 --- a/sqlline.bat +++ b/sqlline.bat @@ -21,10 +21,16 @@ :: > sqlline.bat :: sqlline> !connect jdbc:calcite: admin admin -:: Copy dependency jars on first call. -:: To force jar refresh, remove core\target\dependencies) -if not exist build\libs\sqllineClasspath.jar (call gradlew buildSqllineClasspath) +:: The script updates the classpath on each execution, +:: You might add CACHE_SQLLINE_CLASSPATH environment variable to cache it +:: To build classpath jar manually use gradlew buildSqllineClasspath +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set CP=%DIRNAME%\build\libs\sqllineClasspath.jar -java -Xmx1G -jar build\libs\sqllineClasspath.jar %* +if not defined CACHE_SQLLINE_CLASSPATH ( + if exist "%CP%" del "%CP%" +) +if not exist "%CP%" (call "%DIRNAME%\gradlew" --console plain -q :buildSqllineClasspath) -:: End sqlline.bat +java -Xmx1g -jar "%CP%" %* diff --git a/sqlsh b/sqlsh index 914953677334..1904d9dd3bed 100755 --- a/sqlsh +++ b/sqlsh @@ -19,8 +19,9 @@ # Example: # $ ./sqlsh select \* from du order by 1 limit 3 -# Build classpath on first call. -# (To force rebuild, remove target/fullclasspath.txt.) +# The script updates the classpath on each execution, +# You might use CACHE_SQLLINE_CLASSPATH=Y environment variable to cache it +# To build classpath jar manually use ./gradlew buildSqllineClasspath # Deduce whether we are running cygwin case $(uname -s) in @@ -28,19 +29,20 @@ case $(uname -s) in (*) cygwin=;; esac -root=$(cd "$(dirname "$(readlink $0)")"; pwd) +# readlink in macOS resolves only links, and it returns empty results if the path points to a file +root=$0 +if [[ -L "$root" ]]; then + root=$(readlink "$root") +fi +root=$(cd "$(dirname "$root")"; pwd) CP=$root/build/libs/sqllineClasspath.jar -if [ ! -f $CP ]; then - ( - cd $root - ./gradlew :buildSqllineClasspath - ) + +if [ "x$CACHE_SQLLINE_CLASSPATH" != "xY" ] || [ ! -f "$CP" ]; then + $root/gradlew --console plain -q :buildSqllineClasspath fi VM_OPTS= export JAVA_OPTS=-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl exec java $VM_OPTS -cp "${CP}" $JAVA_OPTS org.apache.calcite.adapter.os.SqlShell "$@" - -# End sqlsh diff --git a/sqlsh.bat b/sqlsh.bat index 2a18de06cbd0..45d7187b0b4e 100644 --- a/sqlsh.bat +++ b/sqlsh.bat @@ -21,10 +21,16 @@ :: > sqlline.bat :: sqlline> !connect jdbc:calcite: admin admin -:: Copy dependency jars on first call. -:: To force jar refresh, remove core\target\dependencies) -if not exist build\libs\sqllineClasspath.jar (call gradlew buildSqllineClasspath) +:: The script updates the classpath on each execution, +:: You might add CACHE_SQLLINE_CLASSPATH environment variable to cache it +:: To build classpath jar manually use gradlew buildSqllineClasspath +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set CP=%DIRNAME%\build\libs\sqllineClasspath.jar -java -Xmx1G -cp build\libs\sqllineClasspath.jar org.apache.calcite.adapter.os.SqlShell %* +if not defined CACHE_SQLLINE_CLASSPATH ( + if exist "%CP%" del "%CP%" +) +if not exist "%CP%" (call "%DIRNAME%\gradlew" --console plain -q :buildSqllineClasspath) -:: End sqlline.bat +java -Xmx1g -cp "%CP%" org.apache.calcite.adapter.os.SqlShell %*