Skip to content

Commit

Permalink
Merge pull request #24 from gisaia/feat/date_type_inference
Browse files Browse the repository at this point in the history
Fix date type inferring to handle - and : in format pattern
  • Loading branch information
sylvaingaudan authored Oct 24, 2024
2 parents c143f79 + d9081fe commit 6de1391
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions arlas/cli/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ def mapping(
if len(tmp) == 2:
types[tmp[0]] = tmp[1]
else:
print("Error: invalid field_mapping \"{}\". The format is \"field:type\" like \"fragment.location:geo_point\"".format(fm), file=sys.stderr)
exit(1)
if tmp[1].startswith("date-"):
# Dates can have format patterns containing ':'
tmp = fm.split(":", 1)
types[tmp[0]] = tmp[1]
else:
print(f"Error: invalid field_mapping \"{fm}\". The format is \"field:type\" like \"fragment.location:geo_point\"", file=sys.stderr)
exit(1)
mapping = make_mapping(file=file, nb_lines=nb_lines, types=types, no_fulltext=no_fulltext)
if push_on and config:
Service.create_index(
Expand Down
3 changes: 2 additions & 1 deletion arlas/cli/model_infering.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def __generate_mapping__(tree, mapping, no_fulltext: list[str]):
__generate_mapping__(v, mapping[k]["properties"], no_fulltext)
else:
if t.startswith("date-"):
mapping[k] = {"type": "date", "format": t.split("-")[1]}
# Dates can have format patterns containing '-'
mapping[k] = {"type": "date", "format": t.split("-", 1)[1]}
else:
mapping[k] = {"type": t}
if t in ["keyword", "text"]:
Expand Down

0 comments on commit 6de1391

Please sign in to comment.