Skip to content

Commit

Permalink
chore(data-warehouse): Add view names into autocomplete (#25517)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilbert09 authored Oct 10, 2024
1 parent 59ac862 commit 7c1ad70
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion posthog/hogql/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_table(self, table_name: str) -> Table:
raise QueryError(f'Unknown table "{table_name}".')

def get_all_tables(self) -> list[str]:
return self._table_names + self._warehouse_table_names
return self._table_names + self._warehouse_table_names + self._view_table_names

def get_posthog_tables(self) -> list[str]:
return self._table_names
Expand Down
28 changes: 28 additions & 0 deletions posthog/hogql/test/test_autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from posthog.models.property_definition import PropertyDefinition
from posthog.schema import HogQLAutocomplete, HogQLAutocompleteResponse, HogLanguage, HogQLQuery, Kind
from posthog.test.base import APIBaseTest, ClickhouseTestMixin
from posthog.warehouse.models.credential import DataWarehouseCredential
from posthog.warehouse.models.datawarehouse_saved_query import DataWarehouseSavedQuery
from posthog.warehouse.models.table import DataWarehouseTable


class TestAutocomplete(ClickhouseTestMixin, APIBaseTest):
Expand Down Expand Up @@ -412,3 +415,28 @@ def test_autocomplete_variables_prefix(self):

assert len(results.suggestions) == 1
assert results.suggestions[0].label == "variable_1"

def test_autocomplete_warehouse_table(self):
credentials = DataWarehouseCredential.objects.create(team=self.team, access_key="key", access_secret="secret")
DataWarehouseTable.objects.create(
team=self.team,
name="some_table",
format="CSV",
url_pattern="http://localhost/file.csv",
credential=credentials,
)
query = "select * from "
results = self._select(query=query, start=14, end=14)

assert "some_table" in [x.label for x in results.suggestions]

def test_autocomplete_warehouse_view(self):
DataWarehouseSavedQuery.objects.create(
team=self.team,
name="some_view",
query={"query": "select * from events"},
)
query = "select * from "
results = self._select(query=query, start=14, end=14)

assert "some_view" in [x.label for x in results.suggestions]

0 comments on commit 7c1ad70

Please sign in to comment.