Skip to content
Open
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
37 changes: 7 additions & 30 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ env:
SNOWSQL_DATABASE: ${{ secrets.SNOWSQL_DATABASE }}
SNOWSQL_SCHEMA: ${{ secrets.SNOWSQL_SCHEMA }}
SNOWSQL_WAREHOUSE: ${{ secrets.SNOWSQL_WAREHOUSE }}
ARTIFACT_NAME: java-sources-${{ github.ref_name }}.jar

jobs:
build:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -30,37 +29,15 @@ jobs:
distribution: 'temurin'
cache: 'maven'

- name: Test and build app
- name: Build and test project
run: mvn package --no-transfer-progress

- name: Rename artifact with commit ID or release name
run: mv ${{ github.workspace }}/target/*.jar ${{ env.ARTIFACT_NAME }}

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: java-app-${{ github.ref_name}}
path: ${{ env.ARTIFACT_NAME }}

deploy:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3 # Necessary for the resources.sql file
- name: Deploy
run: mvn snowflake:deploy --no-transfer-progress

- name: Download artifact from build job
uses: actions/download-artifact@v2
- name: Upload artifact for future reference
uses: actions/upload-artifact@v2
with:
name: java-app-${{ github.ref_name}}
path: target/*.jar

- name: Install SnowSQL
run: |
curl -O https://sfc-repo.snowflakecomputing.com/snowsql/bootstrap/1.2/linux_x86_64/snowsql-1.2.24-linux_x86_64.bash
SNOWSQL_DEST=~/snowflake SNOWSQL_LOGIN_SHELL=~/.profile bash snowsql-1.2.24-linux_x86_64.bash

- name: Deploy jobs
run: |
~/snowflake/snowsql \
-f resources.sql \
-o variable_substitution=true \
--variable artifact_name=${{ env.ARTIFACT_NAME }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ build/

# IDEs
.idea/
.vscode/

.gradle/
18 changes: 18 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"snowflake.snowflake-vsc",
"redhat.java",
"me-dutour-mathieu.vscode-github-actions"
]
}
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"configurations": [
{
"type": "java",
"name": "Launch Java Program",
"request": "launch",
"mainClass": "org.example.procedure.App",
"projectName": "snowpark-java-template"
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.watcherExclude": {
"**/target": true
},
"java.configuration.updateBuildConfiguration": "automatic"
}
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Set the following environment variables with your Snowflake account information:

```bash
# Linux/MacOS
set SNOWSQL_ACCOUNT=<replace with your account identifer>
set SNOWSQL_USER=<replace with your username>
set SNOWSQL_PWD=<replace with your password>
set SNOWSQL_DATABASE=<replace with your database>
set SNOWSQL_SCHEMA=<replace with your schema>
set SNOWSQL_WAREHOUSE=<replace with your warehouse>
export SNOWSQL_ACCOUNT=<replace with your account identifer>
export SNOWSQL_USER=<replace with your username>
export SNOWSQL_PWD=<replace with your password>
export SNOWSQL_DATABASE=<replace with your database>
export SNOWSQL_SCHEMA=<replace with your schema>
export SNOWSQL_WAREHOUSE=<replace with your warehouse>
```

```powershell
Expand All @@ -38,14 +38,13 @@ To develop your applications locally, you will need

## Usage


Once you've set your credentials, you can test your connection by running the `run()` command in [`App.java`](src/main/java/org/example/procedure/App.java). You can run this method directly from your IDE.

You should see the following output in your terminal:

```log
---------------------------------------------------
|"Hello world" |
|"HELLO_WORLD" |
---------------------------------------------------
|Welcome to Snowflake! |
|Learn more: https://www.snowflake.com/snowpark/ |
Expand All @@ -54,14 +53,13 @@ You should see the following output in your terminal:

### Deploy the contents

The GitHub Actions [workflow file](.github/workflows/build-and-deploy.yml) allows you to continously deploy your objects to Snowflake. When you're ready, create secrets in your GitHub repository with the same name and values as the environment variables you created earler (`SNOWSQL_PWD`, `SNOWSQL_ACCOUNT`, etc.). The workflow will create a stage, upload the compiled .jar, and create the stored procedure object. For more information, see [`resources.sql`](resources.sql).
The GitHub Actions [workflow file](.github/workflows/build-and-deploy.yml) allows you to continously deploy your objects to Snowflake whenever a commit is made on the main branch. To set this up, create secrets in your GitHub repository with the same name and values as the environment variables you created earler (`SNOWSQL_PWD`, `SNOWSQL_ACCOUNT`, etc.). The workflow will create a stage, upload the compiled .jar, and create the stored procedure and UDF objects using the [Snowflake Maven plugin](https://github.com/Snowflake-Labs/snowflake-maven-gradle-plugins)

## Project Structure

- [procedure/](src/main/java/org/example/procedure/): Directory for your stored procedures
- [udf/](src/main/java/org/example/udf/): Directory for your user-defined functions
- [util/](src/main/java/org/example/util/): Directory for methods/classes shared between procedures and UDFs
- [resources.sql](resources.sql): A deployment script for your objects
- [build-and-deploy.yaml](.github/workflows/build-and-deploy.yml): A GitHub Actions template to build and deploy your objects

## Docs
Expand Down
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading