diff --git a/CHANGELOG.md b/CHANGELOG.md index ad83f9b..f10571a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) @@ -23,7 +27,7 @@ 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) @@ -31,8 +35,7 @@ All notable changes to this project will be documented in this file using [Seman ## [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) diff --git a/aleph.gemspec b/aleph.gemspec index ff10104..ab61aae 100644 --- a/aleph.gemspec +++ b/aleph.gemspec @@ -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) + diff --git a/app/models/query_execution.rb b/app/models/query_execution.rb index e20b889..a311980 100644 --- a/app/models/query_execution.rb +++ b/app/models/query_execution.rb @@ -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! diff --git a/lib/result_csv_generator.rb b/lib/result_csv_generator.rb index 272df4e..8bb96b2 100644 --- a/lib/result_csv_generator.rb +++ b/lib/result_csv_generator.rb @@ -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