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

Commit dcbfaa1

Browse files
authored
#91 fix error when snowflake returns empty result (#92)
CORE-885
1 parent b8eac6a commit dcbfaa1

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

CHANGELOG.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22
All notable changes to this project will be documented in this file using [Semantic Versioning](http://semver.org/).
33

4+
## [0.4.2] - 2019-09-25
5+
### Fixed
6+
- [Error when Snowflake query returns empty result set](https://github.com/lumoslabs/aleph/issues/91)
7+
48
## [0.4.1] - 2019-09-10
59
### Fixed
610
- [Bug fixes for v0.4.0](https://github.com/lumoslabs/aleph/pull/89)
@@ -23,16 +27,15 @@ All notable changes to this project will be documented in this file using [Seman
2327
- [Site wide, saved filter for schema](https://github.com/lumoslabs/aleph/issues/38)
2428

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

3236
## [0.1.0] - 2017-04-27
3337
### Features
34-
- [Auto-complete on dot](https://github.com/lumoslabs/aleph/issues/48)
35-
38+
- [Auto-complete on dot](https://github.com/lumoslabs/aleph/issues/48)auser
3639
### Fixed
3740
- [change retry configuration for schema query](https://github.com/lumoslabs/aleph/issues/46)
3841

aleph.gemspec

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Gem::Specification.new do |s|
22
s.name = 'aleph_analytics'
3-
s.version = '0.4.1'
4-
s.date = '2019-09-10'
3+
s.version = '0.4.2'
4+
s.date = '2019-09-25'
55
s.summary = 'Redshift/Snowflake analytics platform'
66
s.description = 'The best way to develop and share queries/investigations/results within an analytics team'
7-
s.authors = ['Andrew Xue', 'Rob Froetscher']
8-
s.email = 'andrew@lumoslabs.com'
7+
s.authors = ['Andrew Xue', 'Rob Froetscher', 'Joyce Lau']
8+
s.email = 'eng-data@lumoslabs.com'
99
s.files = Dir.glob('{app,bin,lib,config,vendor}/**/*') +
1010
# need to find the hidden sprockets manifest in public/assets
1111
Dir.glob('public/assets/**/*', File::FNM_DOTMATCH) +

app/models/query_execution.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,16 @@ def self.query_snowflake(connection, body, result, sample_callback)
7373
location = File.join(connection.unload_target, result.current_result_filename)
7474
sql = SNOWFLAKE_UNLOAD_SQL % {location: location, query: body, max_file_size: connection.max_file_size}
7575
row = connection.connection.fetch(sql).first
76-
row_count = row[:rows_unloaded]
76+
row_count = row[:rows_unloaded].to_i
7777

78-
headers, samples = CsvSerializer.load_from_s3_file(result.current_result_s3_key, NUM_SAMPLE_ROWS)
78+
if row_count.zero?
79+
# snowflake unload does not create a file if query returns empty result set; create an empty file
80+
headers = ['']
81+
samples = []
82+
ResultCsvGenerator.new(result.id, headers, true)
83+
else
84+
headers, samples = CsvSerializer.load_from_s3_file(result.current_result_s3_key, NUM_SAMPLE_ROWS)
85+
end
7986

8087
result.headers = headers
8188
result.save!

lib/result_csv_generator.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
class ResultCsvGenerator
44
attr_accessor :csv
55

6-
def initialize(result_id, headers)
6+
def initialize(result_id, headers, create_empty = false)
77
@result_id = result_id
88
@headers = headers
99
@csv_service = CsvService.new(@result_id)
10+
11+
if create_empty
12+
setup_csv.call()
13+
finish_csv.call(0)
14+
end
1015
end
1116

1217
def callbacks

0 commit comments

Comments
 (0)