Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest for ArrayFacet possibly confused by blank values #1246

Closed
simonw opened this issue Feb 26, 2021 · 3 comments
Closed

Suggest for ArrayFacet possibly confused by blank values #1246

simonw opened this issue Feb 26, 2021 · 3 comments

Comments

@simonw
Copy link
Owner

simonw commented Feb 26, 2021

I sometimes don't get the suggestion for facet-by-array for columns that contain arrays. I think it may be because they have empty spaces in them - or perhaps it's because the null detection doesn't actually work.

@simonw
Copy link
Owner Author

simonw commented Feb 26, 2021

Relevant code:

async def suggest(self):
columns = await self.get_columns(self.sql, self.params)
suggested_facets = []
already_enabled = [c["config"]["simple"] for c in self.get_configs()]
for column in columns:
if column in already_enabled:
continue
# Is every value in this column either null or a JSON array?
suggested_facet_sql = """
select distinct json_type({column})
from ({sql})
""".format(
column=escape_sqlite(column), sql=self.sql
)
try:
results = await self.ds.execute(
self.database,
suggested_facet_sql,
self.params,
truncate=False,
custom_time_limit=self.ds.setting("facet_suggest_time_limit_ms"),
log_sql_errors=False,
)
types = tuple(r[0] for r in results.rows)
if types in (("array",), ("array", None)):

@simonw
Copy link
Owner Author

simonw commented Feb 26, 2021

Could I take this part:

             suggested_facet_sql = """ 
                 select distinct json_type({column}) 
                 from ({sql}) 
             """.format( 
                 column=escape_sqlite(column), sql=self.sql 
             ) 

And add where {column} is not null and {column} != '' perhaps?

@simonw
Copy link
Owner Author

simonw commented Mar 1, 2021

I'm going to try a new pattern for testing this, enabled by #1151 - the test will create a new named in-memory database, write some records to it and then run some test facets against that. This will save me from having to add yet another fixtures table for this.

@simonw simonw closed this as completed in 47eb885 Mar 1, 2021
simonw added a commit that referenced this issue Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant