Skip to content

Commit

Permalink
Add timestamp fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bsmartradio committed Jan 3, 2024
1 parent 2b9c5b9 commit 50ed34d
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions python/lsst/alert/packet/updateSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ def populate_fields(apdb_table):
for column in apdb_table['columns']:
# We are still finalizing the time series feature names.

excluded_fields = ['validityStart', 'validityEnd', 'Periodic', 'max', 'min',
excluded_fields = ['validityEnd', 'Periodic', 'max', 'min',
'Science', 'Percentile', 'Max', 'Min', 'science', 'LowzGal',
'MAD', 'Skew', 'Intercept', 'Slope', 'Stetson', 'lastNonForcedSource',
'nDiaSources', 'ExtObj', 'Time', 'time_', 'isDipole', 'bboxSize']
'nDiaSources', 'ExtObj', 'isDipole', 'bboxSize']
exclude = False
for excluded_field in excluded_fields:
if excluded_field in column['name']:
Expand All @@ -79,6 +79,11 @@ def populate_fields(apdb_table):
if not exclude:
if 'char' in column['datatype']:
column['datatype'] = "string"
is_timestamp = 'timestamp' in column['datatype']

if is_timestamp:
column['datatype'] = "long"

# Check if a column is nullable. If it is, it needs a default.
if 'nullable' in column:
if column['nullable'] is False:
Expand All @@ -87,33 +92,36 @@ def populate_fields(apdb_table):
field = {'name': column['name'],
'type': column['datatype'],
'doc': column['description']}
field_dictionary_array.append(field)
else:
field = {'name': column['name'],
'type': column['datatype'], 'doc': ''}
field_dictionary_array.append(field)
else: # nullable == True
if 'description' in column:
field = {'name': column['name'],
'type': ['null', str(column['datatype'])],
'doc': column['description'], 'default': None}
field_dictionary_array.append(field)
else:
field = {'name': column['name'],
'type': ['null', str(column['datatype'])],
'doc': '', 'default': None}
field_dictionary_array.append(field)
else: # nullable not in columns (nullable == True)
if 'description' in column:
field = {'name': column['name'],
'type': ['null', str(column['datatype'])],
'doc': column['description'], 'default': None}
field_dictionary_array.append(field)

else:
field = {"name": column['name'],
"type": ["null", str(column["datatype"])],
"doc": "", "default": None}
field_dictionary_array.append(field)

if is_timestamp:
field['logicalType'] = 'timestamp-micros'
if column['name'] == 'validityStart':
print(field)
field_dictionary_array.append(field)
if column['name'] == 'validityStart':
print(field_dictionary_array[-1])

return field_dictionary_array

Expand Down Expand Up @@ -191,7 +199,8 @@ def generate_schema(apdb_filepath, schema_path, schema_version):
if name in table['name']:
field_dictionary = populate_fields(table)
schema = create_schema(name, field_dictionary, version_name)

if name == 'DiaObject':
print(schema)
write_schema(schema, path)


Expand Down

0 comments on commit 50ed34d

Please sign in to comment.