From 2f0f6fcb62f90a8695fc555e173d0ebe4ddb5d85 Mon Sep 17 00:00:00 2001 From: Raphael Hoffmann Date: Tue, 21 Jun 2016 15:12:51 -0700 Subject: [PATCH 1/2] Adds support for null values in int/float columns in pgtsv_to_json; adds GP data types for floats --- database/pgtsv_to_json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/database/pgtsv_to_json b/database/pgtsv_to_json index cbd5c60e6..999430ea8 100755 --- a/database/pgtsv_to_json +++ b/database/pgtsv_to_json @@ -57,12 +57,14 @@ def convert_type_func(ty, ty_rest = ""): "bigint" : "int", "double" : "float", "numeric" : "float", + "real" : "float", + "double precision" : "float", "unknown" : "text", } convert_for_primitive_types = { "timestamp": timestamp, - "int" : int, - "float" : float, + "int" : lambda x: None if x == 'NULL' else int(x), + "float" : lambda x: None if x == 'NULL' else float(x), "text" : lambda x: unescape_postgres_text_format(x).decode('unicode_escape'), "boolean" : lambda x: x == "t", } From 5369f997e7a904247200dd6fe1637237943c48fd Mon Sep 17 00:00:00 2001 From: Raphael Hoffmann Date: Wed, 22 Jun 2016 10:11:13 -0700 Subject: [PATCH 2/2] Generalize null handling in pgtsv_to_json --- database/pgtsv_to_json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/database/pgtsv_to_json b/database/pgtsv_to_json index 999430ea8..fdd9f4256 100755 --- a/database/pgtsv_to_json +++ b/database/pgtsv_to_json @@ -48,7 +48,8 @@ def convert_type_func(ty, ty_rest = ""): else: def convert_other_array(value): arr = csv.reader([value[1:-1]], delimiter=',', quotechar='"').next() - return map(convert, arr) + convert_or_null = lambda x: None if x == 'NULL' else convert(x) + return map(convert_or_null, arr) return convert_other_array else: # non-array, must be primitive type normalized_type_name = { @@ -63,8 +64,8 @@ def convert_type_func(ty, ty_rest = ""): } convert_for_primitive_types = { "timestamp": timestamp, - "int" : lambda x: None if x == 'NULL' else int(x), - "float" : lambda x: None if x == 'NULL' else float(x), + "int" : int, + "float" : float, "text" : lambda x: unescape_postgres_text_format(x).decode('unicode_escape'), "boolean" : lambda x: x == "t", }