Skip to content

Commit 8df4df0

Browse files
committed
[CALCITE-4324] Avoid sqlline classpath caching by default, add sqlline and sqlsh tests
The classpath caching can be enabled with CACHE_SQLLINE_CLASSPATH=Y environment variable
1 parent 5ae3c16 commit 8df4df0

File tree

11 files changed

+116
-43
lines changed

11 files changed

+116
-43
lines changed

Diff for: .github/workflows/main.yml

+19
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ jobs:
5757
with:
5858
job-id: jdk${{ matrix.jdk }}
5959
arguments: --scan --no-parallel --no-daemon build javadoc
60+
- name: 'sqlline and sqllsh'
61+
shell: cmd
62+
run: |
63+
call sqlline.bat -e '!quit'
64+
echo.
65+
echo Sqlline example/csv
66+
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
67+
echo.
68+
echo sqlsh
69+
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"
6070
6171
linux-avatica:
6272
if: github.event.action != 'labeled'
@@ -109,6 +119,15 @@ jobs:
109119
with:
110120
job-id: jdk15
111121
arguments: --scan --no-parallel --no-daemon build javadoc
122+
- name: 'sqlline and sqllsh'
123+
run: |
124+
./sqlline -e '!quit'
125+
echo
126+
echo Sqlline example/csv
127+
./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
128+
echo
129+
echo sqlsh
130+
./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"
112131
113132
errorprone:
114133
if: github.event.action != 'labeled'

Diff for: .ratignore

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
**/data.txt
1414
**/data2.txt
1515
.idea/vcs.xml
16+
example/csv/src/test/resources/smoke_test.sql
1617

1718
# TODO: remove when pom.xml files are removed
1819
src/main/config/licenses

Diff for: build.gradle.kts

+15-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import org.apache.calcite.buildtools.buildext.dsl.ParenthesisBalancer
3030
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
3131

3232
plugins {
33+
// java-base is needed for platform(...) resolution,
34+
// see https://github.com/gradle/gradle/issues/14822
35+
`java-base`
3336
publishing
3437
// Verification
3538
checkstyle
@@ -175,6 +178,12 @@ val dataSetsForSqlline = listOf(
175178

176179
val sqllineClasspath by configurations.creating {
177180
isCanBeConsumed = false
181+
attributes {
182+
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
183+
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.CLASSES_AND_RESOURCES))
184+
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, JavaVersion.current().majorVersion.toInt())
185+
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
186+
}
178187
}
179188

180189
dependencies {
@@ -196,7 +205,12 @@ val buildSqllineClasspath by tasks.registering(Jar::class) {
196205
manifest {
197206
attributes(
198207
"Main-Class" to "sqlline.SqlLine",
199-
"Class-Path" to provider { sqllineClasspath.joinToString(" ") { it.absolutePath } }
208+
"Class-Path" to provider {
209+
// Class-Path is a list of URLs
210+
sqllineClasspath.joinToString(" ") {
211+
it.toURI().toURL().toString()
212+
}
213+
}
200214
)
201215
}
202216
}

Diff for: example/csv/build.gradle.kts

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ val buildSqllineClasspath by tasks.registering(Jar::class) {
4444
manifest {
4545
attributes(
4646
"Main-Class" to "sqlline.SqlLine",
47-
"Class-Path" to provider { sqllineClasspath.joinToString(" ") { it.absolutePath } }
47+
"Class-Path" to provider {
48+
// Class-Path is a list of URLs
49+
sqllineClasspath.joinToString(" ") {
50+
it.toURI().toURL().toString()
51+
}
52+
}
4853
)
4954
}
5055
}

Diff for: example/csv/sqlline

+12-6
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ case $(uname -s) in
2727
(*) cygwin=;;
2828
esac
2929

30-
# Build classpath on first call. (To update it run ../gradlew buildSqllineClasspath)
31-
cd $(dirname $0)
30+
# readlink in macOS resolves only links, and it returns empty results if the path points to a file
31+
root=$0
32+
if [[ -L "$root" ]]; then
33+
root=$(readlink "$root")
34+
fi
35+
root=$(cd "$(dirname "$root")"; pwd)
36+
37+
CP=$root/build/libs/sqllineClasspath.jar
3238

33-
if [ ! -f build/libs/sqllineClasspath.jar ]; then
34-
../../gradlew buildSqllineClasspath
39+
if [ "x$CACHE_SQLLINE_CLASSPATH" != "xY" ] || [ ! -f "$CP" ]; then
40+
$root/../../gradlew --console plain -q :example:csv:buildSqllineClasspath
3541
fi
3642

3743
VM_OPTS=
@@ -40,6 +46,6 @@ if [ "$cygwin" ]; then
4046
VM_OPTS=-Djline.terminal=jline.UnixTerminal
4147
fi
4248

43-
exec java -Xmx1g $VM_OPTS -jar build/libs/sqllineClasspath.jar "$@"
49+
export JAVA_OPTS=-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
4450

45-
# End sqlline
51+
exec java -Xmx1g $VM_OPTS $JAVA_OPTS -jar "$root/build/libs/sqllineClasspath.jar" "$@"

Diff for: example/csv/sqlline.bat

+12-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@
1919
:: sqlline.bat - Windows script to launch SQL shell
2020
:: Example:
2121
:: > sqlline.bat
22-
:: sqlline> !connect jdbc:calcite:model=target/test-classes/model.json admin admin
22+
:: sqlline> !connect jdbc:calcite:model=src\test\resources\model.json admin admin
2323
:: sqlline> !tables
2424

25-
:: Copy dependency jars on first call. To update it run ./gradlew buildSqllineClasspath
26-
if not exist build\libs\sqllineClasspath.jar (call ../../gradlew buildSqllineClasspath)
25+
:: The script updates the classpath on each execution,
26+
:: You might add CACHE_SQLLINE_CLASSPATH environment variable to cache it
27+
:: To build classpath jar manually use gradlew buildSqllineClasspath
28+
set DIRNAME=%~dp0
29+
if "%DIRNAME%" == "" set DIRNAME=.
30+
set CP=%DIRNAME%\build\libs\sqllineClasspath.jar
2731

28-
java -Xmx1g -jar build\libs\sqllineClasspath.jar sqlline.SqlLine %*
32+
if not defined CACHE_SQLLINE_CLASSPATH (
33+
if exist "%CP%" del "%CP%"
34+
)
35+
if not exist "%CP%" (call "%DIRNAME%\..\..\gradlew" --console plain -q :example:csv:buildSqllineClasspath)
2936

30-
:: End sqlline.bat
37+
java -Xmx1g -jar "%CP%" %*

Diff for: example/csv/src/test/resources/smoke_test.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!tables
2+
3+
select 2 + 2 * 2 as "2+2*2";

Diff for: sqlline

+14-10
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,27 @@
2020
# $ ./sqlline
2121
# sqlline> !connect jdbc:calcite: admin admin
2222

23+
# The script updates the classpath on each execution,
24+
# You might use CACHE_SQLLINE_CLASSPATH=Y environment variable to cache it
25+
# To build classpath jar manually use ./gradlew buildSqllineClasspath
26+
2327
# Deduce whether we are running cygwin
2428
case $(uname -s) in
2529
(CYGWIN*) cygwin=true;;
2630
(*) cygwin=;;
2731
esac
2832

29-
# Build classpath on first call. To update it run ./gradlew buildSqllineClasspath
30-
root=$(cd "$(dirname "$(readlink $0)")"; pwd)
33+
# readlink in macOS resolves only links, and it returns empty results if the path points to a file
34+
root=$0
35+
if [[ -L "$root" ]]; then
36+
root=$(readlink "$root")
37+
fi
38+
root=$(cd "$(dirname "$root")"; pwd)
3139

3240
CP=$root/build/libs/sqllineClasspath.jar
33-
if [ ! -f $CP ]; then
34-
(
35-
cd $root
36-
./gradlew :buildSqllineClasspath
37-
)
41+
42+
if [ "x$CACHE_SQLLINE_CLASSPATH" != "xY" ] || [ ! -f "$CP" ]; then
43+
$root/gradlew --console plain -q :buildSqllineClasspath
3844
fi
3945

4046
VM_OPTS=
@@ -45,6 +51,4 @@ fi
4551

4652
export JAVA_OPTS=-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
4753

48-
exec java -Xmx1g $VM_OPTS $JAVA_OPTS -jar build/libs/sqllineClasspath.jar "$@"
49-
50-
# End sqlline
54+
exec java -Xmx1g $VM_OPTS $JAVA_OPTS -jar "$root/build/libs/sqllineClasspath.jar" "$@"

Diff for: sqlline.bat

+11-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
2121
:: > sqlline.bat
2222
:: sqlline> !connect jdbc:calcite: admin admin
2323

24-
:: Copy dependency jars on first call.
25-
:: To force jar refresh, remove core\target\dependencies)
26-
if not exist build\libs\sqllineClasspath.jar (call gradlew buildSqllineClasspath)
24+
:: The script updates the classpath on each execution,
25+
:: You might add CACHE_SQLLINE_CLASSPATH environment variable to cache it
26+
:: To build classpath jar manually use gradlew buildSqllineClasspath
27+
set DIRNAME=%~dp0
28+
if "%DIRNAME%" == "" set DIRNAME=.
29+
set CP=%DIRNAME%\build\libs\sqllineClasspath.jar
2730

28-
java -Xmx1G -jar build\libs\sqllineClasspath.jar %*
31+
if not defined CACHE_SQLLINE_CLASSPATH (
32+
if exist "%CP%" del "%CP%"
33+
)
34+
if not exist "%CP%" (call "%DIRNAME%\gradlew" --console plain -q :buildSqllineClasspath)
2935

30-
:: End sqlline.bat
36+
java -Xmx1g -jar "%CP%" %*

Diff for: sqlsh

+12-10
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,30 @@
1919
# Example:
2020
# $ ./sqlsh select \* from du order by 1 limit 3
2121

22-
# Build classpath on first call.
23-
# (To force rebuild, remove target/fullclasspath.txt.)
22+
# The script updates the classpath on each execution,
23+
# You might use CACHE_SQLLINE_CLASSPATH=Y environment variable to cache it
24+
# To build classpath jar manually use ./gradlew buildSqllineClasspath
2425

2526
# Deduce whether we are running cygwin
2627
case $(uname -s) in
2728
(CYGWIN*) cygwin=true;;
2829
(*) cygwin=;;
2930
esac
3031

31-
root=$(cd "$(dirname "$(readlink $0)")"; pwd)
32+
# readlink in macOS resolves only links, and it returns empty results if the path points to a file
33+
root=$0
34+
if [[ -L "$root" ]]; then
35+
root=$(readlink "$root")
36+
fi
37+
root=$(cd "$(dirname "$root")"; pwd)
3238

3339
CP=$root/build/libs/sqllineClasspath.jar
34-
if [ ! -f $CP ]; then
35-
(
36-
cd $root
37-
./gradlew :buildSqllineClasspath
38-
)
40+
41+
if [ "x$CACHE_SQLLINE_CLASSPATH" != "xY" ] || [ ! -f "$CP" ]; then
42+
$root/gradlew --console plain -q :buildSqllineClasspath
3943
fi
4044

4145
VM_OPTS=
4246
export JAVA_OPTS=-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
4347

4448
exec java $VM_OPTS -cp "${CP}" $JAVA_OPTS org.apache.calcite.adapter.os.SqlShell "$@"
45-
46-
# End sqlsh

Diff for: sqlsh.bat

+11-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
2121
:: > sqlline.bat
2222
:: sqlline> !connect jdbc:calcite: admin admin
2323

24-
:: Copy dependency jars on first call.
25-
:: To force jar refresh, remove core\target\dependencies)
26-
if not exist build\libs\sqllineClasspath.jar (call gradlew buildSqllineClasspath)
24+
:: The script updates the classpath on each execution,
25+
:: You might add CACHE_SQLLINE_CLASSPATH environment variable to cache it
26+
:: To build classpath jar manually use gradlew buildSqllineClasspath
27+
set DIRNAME=%~dp0
28+
if "%DIRNAME%" == "" set DIRNAME=.
29+
set CP=%DIRNAME%\build\libs\sqllineClasspath.jar
2730

28-
java -Xmx1G -cp build\libs\sqllineClasspath.jar org.apache.calcite.adapter.os.SqlShell %*
31+
if not defined CACHE_SQLLINE_CLASSPATH (
32+
if exist "%CP%" del "%CP%"
33+
)
34+
if not exist "%CP%" (call "%DIRNAME%\gradlew" --console plain -q :buildSqllineClasspath)
2935

30-
:: End sqlline.bat
36+
java -Xmx1g -cp "%CP%" org.apache.calcite.adapter.os.SqlShell %*

0 commit comments

Comments
 (0)