Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nector-nodejs into SNOW-728803-request-id-sqlText
  • Loading branch information
sfc-gh-ext-simba-lf committed Oct 5, 2023
2 parents 7d4b23c + 40f370c commit b0467dc
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 418 deletions.
66 changes: 52 additions & 14 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Build
shell: bash
env:
WHITESOURCE_API_KEY: ${{ secrets.WHITESOURCE_API_KEY }}
run: ./ci/build.sh
- name: Upload Build Artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: artifacts
path: artifacts
Expand All @@ -49,19 +49,20 @@ jobs:
fail-fast: false
matrix:
cloud: [ 'AWS', 'AZURE', 'GCP' ]
nodeVersion: [ '14.x', '16.x', '18.x']
nodeVersion: [ '14.x', '16.x', '18.x', '20.x']
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.nodeVersion }}
- uses: actions/setup-python@v1
- uses: actions/setup-python@v4
with:
python-version: '3.7'
- name: Download Build Artifacts
uses: actions/download-artifact@v1
uses: actions/download-artifact@v3
with:
name: artifacts
path: artifacts
- name: Install Homebrew Bash
shell: bash
run: brew install bash
Expand All @@ -86,20 +87,21 @@ jobs:
fail-fast: false
matrix:
cloud: [ 'AWS', 'AZURE', 'GCP' ]
nodeVersion: [ '14.x', '16.x', '18.x']
nodeVersion: [ '14.x', '16.x', '18.x', '20.x']
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.nodeVersion }}
- uses: actions/setup-python@v1
- uses: actions/setup-python@v4
with:
python-version: '3.7'
architecture: 'x64'
- name: Download Build Artifacts
uses: actions/download-artifact@v1
uses: actions/download-artifact@v3
with:
name: artifacts
path: artifacts
- name: Tests
shell: cmd
env:
Expand All @@ -117,15 +119,51 @@ jobs:
image: [ 'nodejs-centos7-node14', 'nodejs-centos7-fips']
cloud: [ 'AWS', 'AZURE', 'GCP' ]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Download Build Artifacts
uses: actions/download-artifact@v1
uses: actions/download-artifact@v3
with:
name: artifacts
path: artifacts
- name: Tests
shell: bash
env:
PARAMETERS_SECRET: ${{ secrets.PARAMETERS_SECRET }}
CLOUD_PROVIDER: ${{ matrix.cloud }}
TARGET_DOCKER_TEST_IMAGE: ${{ matrix.image }}
run: ./ci/test.sh

test-ubuntu:
needs: build
name: Tests on Ubuntu
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
cloud: [ 'AWS', 'AZURE', 'GCP' ]
nodeVersion: ['18.x', '20.x']
steps:
- uses: actions/checkout@v4
- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: artifacts
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Tests
shell: bash
env:
PARAMETERS_SECRET: ${{ secrets.PARAMETERS_SECRET }}
CLOUD_PROVIDER: ${{ matrix.cloud }}
run: ./ci/test_ubuntu.sh
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
# without the token code cov may fail because of Github limits https://github.com/codecov/codecov-action/issues/557
token: ${{ secrets.CODE_COV_UPLOAD_TOKEN }}
fail_ci_if_error: true


4 changes: 4 additions & 0 deletions ci/test_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
#
# Test NodeJS for Mac
#

echo "DOWNLOADED"
echo $(ls /Users/runner/work/snowflake-connector-nodejs/snowflake-connector-nodejs/)
set -o pipefail
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $THIS_DIR/_init.sh
source $THIS_DIR/scripts/set_git_info.sh


export WORKSPACE=$GITHUB_WORKSPACE
export SOURCE_ROOT=$GITHUB_WORKSPACE
export SHOULD_GENERATE_COVERAGE_REPORT=1
Expand Down
23 changes: 23 additions & 0 deletions ci/test_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -e
#
# Test NodeJS for Ubuntu
#

echo "DOWNLOADED"
echo $(ls /Users/runner/work/snowflake-connector-nodejs/snowflake-connector-nodejs/)
set -o pipefail
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $THIS_DIR/_init.sh
source $THIS_DIR/scripts/set_git_info.sh

export WORKSPACE=$GITHUB_WORKSPACE
export SOURCE_ROOT=$GITHUB_WORKSPACE
export SHOULD_GENERATE_COVERAGE_REPORT=1
export SHOULD_SKIP_PROXY_TESTS=1

python3 --version
python3 -m venv venv
source venv/bin/activate
pip3 install -U pip
pip3 install -U snowflake-connector-python
$THIS_DIR/container/test_component.sh $SHOULD_GENERATE_COVERAGE_REPORT
8 changes: 7 additions & 1 deletion samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ npm run jsonParserComparison 300000 300000 Function
or
```
npm run jsonParserComparison 300000 300000 JSON
```
```

Run query reading all rows vs streaming the rows
----------------------------------------------------------------------

1. Set your query in [`rowsVsStreamingQuery.js`](./rowsVsStreamingQuery.js)`
2. Run `npm run rowsVsStreamingQuery`
14 changes: 13 additions & 1 deletion samples/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const snowflake = require('snowflake-sdk');

exports.executeQuery = async function (connection, query, binds) {
await new Promise((resolve, reject) => {
connection.execute({
Expand Down Expand Up @@ -53,4 +54,15 @@ exports.connectUsingEnv = async () => {
}
);
});
};
};

exports.destroyAsync = connection => new Promise((resolve, reject) => {
connection.destroy(err => {
if (err) {
reject(err);
} else {
resolve();
}
}
);
});
5 changes: 3 additions & 2 deletions samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"dependencies": {
"better-eval": "^1.3.0",
"blocked-at": "^1.2.0",
"snowflake-sdk": "^1.8.0",
"snowflake-sdk": "^1.9.0",
"vm": "^0.1.0"
},
"scripts": {
"jsonParserComparison": "node jsonParserComparison.js"
"jsonParserComparison": "node jsonParserComparison.js",
"rowsVsStreamingQuery": "node rowsVsStreamingQuery.js"
}
}
55 changes: 55 additions & 0 deletions samples/rowsVsStreamingQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable no-console */
const snowflake = require('snowflake-sdk');
const { connectUsingEnv, destroyAsync } = require('./helpers');

const executeQuery = (connection, query, binds = undefined) => new Promise((resolve, reject) => {
connection.execute({
sqlText: query,
binds: binds,
complete: function (err, stmt, rows) {
if (!err) {
resolve(rows);
} else {
reject(err);
}
}
});
});

const executeQueryStreaming = (connection, query, binds = undefined) => new Promise((resolve, reject) => {
const stmt = connection.execute({
sqlText: query,
binds: binds,
streamResult: true,
});
stmt.streamRows()
.on('error', err => reject(err))
.on('data', () => {})
.on('end', () => resolve());
});

async function runQueryReadingResultsFromRows(query){
const connection = await connectUsingEnv();
console.time('without streaming');
await executeQuery(connection, query);
console.timeEnd('without streaming');
await destroyAsync(connection);
}

async function runQueryReadingResultsFromStream(query){
const connection = await connectUsingEnv();
console.time('with streaming');
await executeQueryStreaming(connection, query);
console.timeEnd('with streaming');
await destroyAsync(connection);
}

async function main() {
const query = 'Select 1'; // Set your query here
snowflake.configure({ logLevel: 'ERROR' });
console.log(`Executing query: ${query}`);
await runQueryReadingResultsFromRows(query);
await runQueryReadingResultsFromStream(query);
}

main();
Loading

0 comments on commit b0467dc

Please sign in to comment.