Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
#91 fix error when snowflake returns empty result (#92)
Browse files Browse the repository at this point in the history
CORE-885
  • Loading branch information
joycelau1 authored Sep 28, 2019
1 parent b8eac6a commit dcbfaa1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file using [Semantic Versioning](http://semver.org/).

## [0.4.2] - 2019-09-25
### Fixed
- [Error when Snowflake query returns empty result set](https://github.com/lumoslabs/aleph/issues/91)

## [0.4.1] - 2019-09-10
### Fixed
- [Bug fixes for v0.4.0](https://github.com/lumoslabs/aleph/pull/89)
Expand All @@ -23,16 +27,15 @@ All notable changes to this project will be documented in this file using [Seman
- [Site wide, saved filter for schema](https://github.com/lumoslabs/aleph/issues/38)

### Fixed
- [Use trusty for travis](https://github.com/lumoslabs/aleph/issues/67)
- [Use trusty for travis](https://github.com/lumoslabs/al eph/issues/67)
- [Display 24-hour format](https://github.com/lumoslabs/aleph/issues/53)
- [Schema search should be able to handle numbers](https://github.com/lumoslabs/aleph/issues/59)
- [Clean up /tmp result files when query fails](https://github.com/lumoslabs/aleph/issues/37)
- [Increase schema query reties](https://github.com/lumoslabs/aleph/issues/64)

## [0.1.0] - 2017-04-27
### Features
- [Auto-complete on dot](https://github.com/lumoslabs/aleph/issues/48)

- [Auto-complete on dot](https://github.com/lumoslabs/aleph/issues/48)auser
### Fixed
- [change retry configuration for schema query](https://github.com/lumoslabs/aleph/issues/46)

Expand Down
8 changes: 4 additions & 4 deletions aleph.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Gem::Specification.new do |s|
s.name = 'aleph_analytics'
s.version = '0.4.1'
s.date = '2019-09-10'
s.version = '0.4.2'
s.date = '2019-09-25'
s.summary = 'Redshift/Snowflake analytics platform'
s.description = 'The best way to develop and share queries/investigations/results within an analytics team'
s.authors = ['Andrew Xue', 'Rob Froetscher']
s.email = 'andrew@lumoslabs.com'
s.authors = ['Andrew Xue', 'Rob Froetscher', 'Joyce Lau']
s.email = 'eng-data@lumoslabs.com'
s.files = Dir.glob('{app,bin,lib,config,vendor}/**/*') +
# need to find the hidden sprockets manifest in public/assets
Dir.glob('public/assets/**/*', File::FNM_DOTMATCH) +
Expand Down
11 changes: 9 additions & 2 deletions app/models/query_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ def self.query_snowflake(connection, body, result, sample_callback)
location = File.join(connection.unload_target, result.current_result_filename)
sql = SNOWFLAKE_UNLOAD_SQL % {location: location, query: body, max_file_size: connection.max_file_size}
row = connection.connection.fetch(sql).first
row_count = row[:rows_unloaded]
row_count = row[:rows_unloaded].to_i

headers, samples = CsvSerializer.load_from_s3_file(result.current_result_s3_key, NUM_SAMPLE_ROWS)
if row_count.zero?
# snowflake unload does not create a file if query returns empty result set; create an empty file
headers = ['']
samples = []
ResultCsvGenerator.new(result.id, headers, true)
else
headers, samples = CsvSerializer.load_from_s3_file(result.current_result_s3_key, NUM_SAMPLE_ROWS)
end

result.headers = headers
result.save!
Expand Down
7 changes: 6 additions & 1 deletion lib/result_csv_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
class ResultCsvGenerator
attr_accessor :csv

def initialize(result_id, headers)
def initialize(result_id, headers, create_empty = false)
@result_id = result_id
@headers = headers
@csv_service = CsvService.new(@result_id)

if create_empty
setup_csv.call()
finish_csv.call(0)
end
end

def callbacks
Expand Down

0 comments on commit dcbfaa1

Please sign in to comment.