Skip to content

Commit

Permalink
[CALCITE-4324] Avoid sqlline classpath caching by default, add sqllin…
Browse files Browse the repository at this point in the history
…e and sqlsh tests

The classpath caching can be enabled with CACHE_SQLLINE_CLASSPATH=Y environment variable
  • Loading branch information
vlsi committed Oct 10, 2020
1 parent 5ae3c16 commit 8df4df0
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 43 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions .ratignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}
}
)
}
}
Expand Down
7 changes: 6 additions & 1 deletion example/csv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
)
}
}
18 changes: 12 additions & 6 deletions example/csv/sqlline
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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" "$@"
17 changes: 12 additions & 5 deletions example/csv/sqlline.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%" %*
3 changes: 3 additions & 0 deletions example/csv/src/test/resources/smoke_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!tables

select 2 + 2 * 2 as "2+2*2";
24 changes: 14 additions & 10 deletions sqlline
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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" "$@"
16 changes: 11 additions & 5 deletions sqlline.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%" %*
22 changes: 12 additions & 10 deletions sqlsh
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,30 @@
# 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
(CYGWIN*) cygwin=true;;
(*) 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
16 changes: 11 additions & 5 deletions sqlsh.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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 %*

0 comments on commit 8df4df0

Please sign in to comment.