-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Snowflake Container Service
- Loading branch information
Showing
12 changed files
with
229 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM openjdk:8-jdk-alpine | ||
WORKDIR /app | ||
COPY bin /app/bin | ||
COPY config /app/config | ||
COPY importlibs /app/importlibs | ||
COPY jdbc /app/jdbc | ||
COPY lib /app/lib | ||
COPY mainPath /app/mainPath | ||
COPY target /app/target | ||
# Set executable permission for esprocx.sh | ||
RUN chmod +x /app/bin/ServerConsole2.sh | ||
ENTRYPOINT ["/bin/sh", "/app/bin/ServerConsole2.sh", "-h"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
## Setting Up the Environment for Snowflake SPL Service | ||
|
||
This guide will walk you through installing the required tools, building and uploading the project image, and creating the compute pool and SPL service in Snowflake. | ||
|
||
### 1. Install JDK 1.8 | ||
|
||
The project requires **JDK 1.8**. Please download it from [Oracle's website](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html) and set the appropriate `JAVA_HOME` environment variable. | ||
|
||
To verify that JDK is installed correctly, run: | ||
```bash | ||
java -version | ||
``` | ||
Make sure the output shows the correct version (Java 1.8). | ||
|
||
### 2. Install Maven | ||
|
||
You also need to install **Maven**. On macOS, it can be easily installed via [Homebrew](https://brew.sh/): | ||
```bash | ||
brew install maven | ||
``` | ||
To verify Maven installation, run: | ||
```bash | ||
mvn -version | ||
``` | ||
Ensure that the version output matches your requirements. | ||
|
||
### 3. Build and Upload the Docker Image | ||
|
||
We provide a script to **build** the project and **upload** the resulting Docker image to a repository managed by Snowflake. You can customize the repository location if needed. | ||
|
||
Before running the script, set your Snowflake account as an environment variable: | ||
```bash | ||
export SNOWFLAKE_ACCOUNT=your-snowflake-account | ||
``` | ||
Then run the build script: | ||
```bash | ||
./build.sh | ||
``` | ||
This script will build the Docker image and upload it to the Snowflake-managed Docker repository. | ||
|
||
### 4. Create the Compute Pool and SPL Service in Snowflake | ||
|
||
To create the SPL service in Snowflake, run the following SQL command in your Snowflake workbook. This command will create a service that provides endpoints to execute SPL files saved in the specified path. | ||
```sql | ||
CREATE SERVICE spl_service | ||
IN COMPUTE POOL tutorial_compute_pool | ||
FROM SPECIFICATION $$ | ||
spec: | ||
container: | ||
- name: main | ||
image: /tutorial_db/data_schema/tutorial_repository/spl_service:latest | ||
env: | ||
SNOWFLAKE_WAREHOUSE: tutorial_warehouse | ||
volumeMounts: | ||
- name: data | ||
mountPath: /opt/data | ||
endpoints: | ||
- name: spl | ||
port: 8502 | ||
public: true | ||
volumes: | ||
- name: data | ||
source: "@tutorial_stage" | ||
$$ | ||
MIN_INSTANCES=1 | ||
MAX_INSTANCES=1; | ||
``` | ||
|
||
The service will provide endpoints to allow users to execute SPL files located in the main path, which is backed by the stage. As long as the SPL file is in the stage, it can be executed via REST APIs. | ||
|
||
To **check the status** of the service or **retrieve logs**, use the following SQL commands: | ||
```sql | ||
SELECT SYSTEM$GET_SERVICE_STATUS('spl_service'); | ||
SELECT SYSTEM$GET_SERVICE_LOGS('spl_service', '0', 'main'); | ||
``` | ||
|
||
### 5. Execute SPL Using REST API | ||
|
||
To execute SPL via REST API, first get the service endpoint: | ||
```sql | ||
SHOW ENDPOINTS IN SERVICE spl_service; | ||
``` | ||
|
||
From the result, copy the `ingress_url` and paste it into your web browser (e.g., Chrome). You can then invoke the SPL using a REST API request like this: | ||
```bash | ||
https://your-ingress-url.snowflakecomputing.app/file_test.splx() | ||
``` | ||
Replace `your-ingress-url` with the actual URL obtained from the `SHOW ENDPOINTS` command. | ||
|
||
This assumes that both the `file_test.splx` and any relevant data are in the `mainPath` backed by the stage. | ||
|
||
### 6. Upload Data and SPL Files to Snowflake Stage | ||
|
||
To upload data or SPL files into the Snowflake stage, use **SnowSQL** (see [SnowSQL documentation](https://docs.snowflake.com/en/user-guide/snowsql)). For example, to upload the `employee.btx` file: | ||
```sql | ||
PUT file:////path-to-esproc/mainPath/employee.btx @tutorial_stage | ||
AUTO_COMPRESS=FALSE | ||
OVERWRITE=TRUE; | ||
``` | ||
Change `path-to-esproc` to the actual path on your machine. This command will place the file into the `tutorial_stage`, making it accessible for SPL execution. | ||
|
||
### Summary | ||
|
||
In this guide, you've set up your environment, built the project Docker image, created a Snowflake SPL service, and learned how to execute SPL files. Make sure to verify each step, ensuring everything is correctly configured for smooth operation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
source /app/bin/setEnv2.sh | ||
"$EXEC_JAVA" -Xms128m -Xmx1024m -cp "$START_HOME"/app/target/classes:"$START_HOME"/app/lib/*:"$START_HOME"/jdbc/* -Duser.language="$language" -Dstart.home="$START_HOME"/app com.scudata.ide.spl.ServerConsole $1 $2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
START_HOME=/ | ||
JAVA_HOME=/usr/bin/ | ||
EXEC_JAVA=$JAVA_HOME/java | ||
language=en |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
# Input arguments with default fallbacks | ||
SNOWFLAKE_ACCOUNT=${1:-$SNOWFLAKE_ACCOUNT} | ||
REPOSITORY_NAME=${2:-$REPOSITORY_NAME} | ||
|
||
# Validate inputs | ||
if [ -z "$SNOWFLAKE_ACCOUNT" ]; then | ||
echo "Error: Snowflake account not specified." | ||
echo "Usage: $0 <snowflake_account> [repository_name] or set SNOWFLAKE_ACCOUNT environment variable." | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$REPOSITORY_NAME" ]; then | ||
REPOSITORY_NAME="tutorial_db/data_schema/tutorial_repository" | ||
echo "Repository not specified. Using default: $REPOSITORY_NAME" | ||
fi | ||
|
||
# Construct dynamic variables | ||
IMAGE_HOST="$SNOWFLAKE_ACCOUNT.registry.snowflakecomputing.com" | ||
REPOSITORY="$IMAGE_HOST/$REPOSITORY_NAME" | ||
IMAGE_NAME="$REPOSITORY/spl-service:latest" | ||
|
||
# Maven clean and package | ||
echo "Building Maven project..." | ||
mvn clean package -Prelease || { echo "Maven build failed! Exiting."; exit 1; } | ||
|
||
# Docker build and push | ||
echo "Building Docker image..." | ||
docker build --rm --platform linux/amd64 -t "$IMAGE_NAME" . || { echo "Docker build failed! Exiting."; exit 1; } | ||
|
||
echo "Pushing Docker image..." | ||
docker push "$IMAGE_NAME" || { echo "Docker push failed! Exiting."; exit 1; } | ||
|
||
echo "Docker image pushed successfully: $IMAGE_NAME" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
CREATE SERVICE spl_service | ||
IN COMPUTE POOL tutorial_compute_pool | ||
FROM SPECIFICATION $$ | ||
spec: | ||
container: | ||
- name: main | ||
image: /tutorial_db/data_schema/tutorial_repository/spl_service:latest | ||
env: | ||
SNOWFLAKE_WAREHOUSE: tutorial_warehouse | ||
volumeMounts: | ||
- name: data | ||
mountPath: /opt/data | ||
endpoints: | ||
- name: spl | ||
port: 8502 | ||
public: true | ||
volumes: | ||
- name: data | ||
source: "@tutorial_stage" | ||
$$ | ||
MIN_INSTANCES=1 | ||
MAX_INSTANCES=1; | ||
|
||
ALTER SERVICE spl_service | ||
FROM SPECIFICATION $$ | ||
spec: | ||
container: | ||
- name: main | ||
image: /tutorial_db/data_schema/tutorial_repository/spl_service:latest | ||
env: | ||
SNOWFLAKE_WAREHOUSE: tutorial_warehouse | ||
volumeMounts: | ||
- name: data | ||
mountPath: /opt/data | ||
endpoints: | ||
- name: spl | ||
port: 8502 | ||
public: true | ||
volumes: | ||
- name: data | ||
source: "@tutorial_stage" | ||
$$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
spec: | ||
container: | ||
- name: main | ||
image: /tutorial_db/data_schema/tutorial_repository/spl_service:latest | ||
env: | ||
SNOWFLAKE_WAREHOUSE: tutorial_warehouse | ||
volumeMounts: | ||
- name: data | ||
mountPath: /opt/data | ||
endpoints: | ||
- name: spl | ||
port: 8503 | ||
public: true | ||
volumes: | ||
- name: data | ||
source: "@tutorial_stage" |