JSON faceting now suggested even if column has blank strings, closes #1246

This commit is contained in:
Simon Willison 2021-02-28 19:44:04 -08:00
commit 47eb885cc2
2 changed files with 30 additions and 3 deletions

View file

@ -279,6 +279,7 @@ class ArrayFacet(Facet):
suggested_facet_sql = """
select distinct json_type({column})
from ({sql})
where {column} is not null and {column} != ''
""".format(
column=escape_sqlite(column), sql=self.sql
)
@ -298,9 +299,13 @@ class ArrayFacet(Facet):
v[0]
for v in await self.ds.execute(
self.database,
"select {column} from ({sql}) where {column} is not null and json_array_length({column}) > 0 limit 100".format(
column=escape_sqlite(column), sql=self.sql
),
(
"select {column} from ({sql}) "
"where {column} is not null "
"and {column} != '' "
"and json_array_length({column}) > 0 "
"limit 100"
).format(column=escape_sqlite(column), sql=self.sql),
self.params,
truncate=False,
custom_time_limit=self.ds.setting(