diff --git a/posthog/hogql/database/database.py b/posthog/hogql/database/database.py index cd34885f24e3a..e1e3fd26f8203 100644 --- a/posthog/hogql/database/database.py +++ b/posthog/hogql/database/database.py @@ -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 diff --git a/posthog/hogql/test/test_autocomplete.py b/posthog/hogql/test/test_autocomplete.py index 936944057289b..04f62bb0bdabc 100644 --- a/posthog/hogql/test/test_autocomplete.py +++ b/posthog/hogql/test/test_autocomplete.py @@ -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): @@ -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]