Skip to content

Commit

Permalink
Bug fix/XSUP-44464/big-query handle bytes (demisto#37534)
Browse files Browse the repository at this point in the history
* Google BigQuery handle bytes result

* RN

* CR fixes

* Update Packs/GoogleBigQuery/ReleaseNotes/1_1_9.md

Co-authored-by: ShirleyDenkberg <62508050+ShirleyDenkberg@users.noreply.github.com>

---------

Co-authored-by: ShirleyDenkberg <62508050+ShirleyDenkberg@users.noreply.github.com>
  • Loading branch information
MosheEichler and ShirleyDenkberg authored Dec 3, 2024
1 parent e9bbb22 commit b1ab883
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
19 changes: 10 additions & 9 deletions Packs/GoogleBigQuery/Integrations/GoogleBigQuery/GoogleBigQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ def build_query_job_config(allow_large_results, default_dataset_string, destinat
return query_job_config


def convert_to_string_if_datetime(object_that_may_be_datetime):
if isinstance(object_that_may_be_datetime, datetime):
return object_that_may_be_datetime.strftime("%m/%d/%Y %H:%M:%S")
if isinstance(object_that_may_be_datetime, date):
return object_that_may_be_datetime.strftime("%m/%d/%Y")
else:
return object_that_may_be_datetime
def convert_to_string(field_value):
if isinstance(field_value, datetime):
return field_value.strftime("%m/%d/%Y %H:%M:%S")
if isinstance(field_value, date):
return field_value.strftime("%m/%d/%Y")
if isinstance(field_value, bytes):
return field_value.decode('utf-8')
return field_value


''' COMMANDS + REQUESTS FUNCTIONS '''
Expand Down Expand Up @@ -166,7 +167,7 @@ def query_command(query_to_run=None):
else:

for row in query_results:
row_context = {underscoreToCamelCase(k): convert_to_string_if_datetime(v) for k, v in row.items()}
row_context = {underscoreToCamelCase(k): convert_to_string(v) for k, v in row.items()}
rows_contexts.append(row_context)

if rows_contexts:
Expand Down Expand Up @@ -241,7 +242,7 @@ def row_to_incident(row):
Transform a Google BigQuery row to an incident's format.
"""
incident = {}
raw = {underscoreToCamelCase(k): convert_to_string_if_datetime(v) for k, v in row.items()}
raw = {underscoreToCamelCase(k): convert_to_string(v) for k, v in row.items()}
incident["rawJSON"] = json.dumps(raw)
incident_name_field = demisto.params().get("incident_name_field")
if incident_name_field and incident_name_field in raw:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import demistomock as demisto


def test_convert_to_string_if_datetime():
from GoogleBigQuery import convert_to_string_if_datetime
test_conversion_for_none = convert_to_string_if_datetime(None)
def test_convert_to_string():
from GoogleBigQuery import convert_to_string
test_conversion_for_none = convert_to_string(None)
assert test_conversion_for_none is None

now = datetime.datetime.now()
convert_to_string_if_datetime(now)
test_conversion_for_empty_string = convert_to_string_if_datetime("")
convert_to_string(now)
test_conversion_for_empty_string = convert_to_string("")
assert test_conversion_for_empty_string == ""

today = datetime.date.today()
convert_to_string_if_datetime(today)
test_conversion_for_empty_string = convert_to_string_if_datetime("")
convert_to_string(today)
test_conversion_for_empty_string = convert_to_string("")
assert test_conversion_for_empty_string == ""

assert convert_to_string(b'test') == 'test'
assert convert_to_string('test') == 'test'


def test_remove_outdated_incident_ids_keep_equal():
"""
Expand Down
6 changes: 6 additions & 0 deletions Packs/GoogleBigQuery/ReleaseNotes/1_1_9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Google BigQuery

Fixed an issue where the ***bigquery-query*** command failed when the query result includes bytes.
2 changes: 1 addition & 1 deletion Packs/GoogleBigQuery/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Google BigQuery",
"description": "Integration for Google BigQuery, a data warehouse for querying and analyzing large databases. In all commands, for any argument not specified, the BigQuery default value for that argument will be applied.",
"support": "xsoar",
"currentVersion": "1.1.8",
"currentVersion": "1.1.9",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit b1ab883

Please sign in to comment.