mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
[Jinja] Make Presto template functions backwards compatible (#7993)
This commit is contained in:
committed by
michellethomas
parent
b380879c41
commit
cd6de3a1d8
@@ -56,7 +56,7 @@ Templating with Jinja
|
||||
|
||||
SELECT *
|
||||
FROM some_table
|
||||
WHERE partition_key = '{{ presto.latest_partition('some_table') }}'
|
||||
WHERE partition_key = '{{ presto.first_latest_partition('some_table') }}'
|
||||
|
||||
Templating unleashes the power and capabilities of a
|
||||
programming language within your SQL code.
|
||||
|
||||
@@ -240,7 +240,25 @@ class PrestoTemplateProcessor(BaseTemplateProcessor):
|
||||
schema, table_name = table_name.split(".")
|
||||
return table_name, schema
|
||||
|
||||
def latest_partition(self, table_name: str):
|
||||
def first_latest_partition(self, table_name: str) -> str:
|
||||
"""
|
||||
Gets the first value in the array of all latest partitions
|
||||
|
||||
:param table_name: table name in the format `schema.table`
|
||||
:return: the first (or only) value in the latest partition array
|
||||
:raises IndexError: If no partition exists
|
||||
"""
|
||||
|
||||
return self.latest_partitions(table_name)[0]
|
||||
|
||||
def latest_partitions(self, table_name: str) -> List[str]:
|
||||
"""
|
||||
Gets the array of all latest partitions
|
||||
|
||||
:param table_name: table name in the format `schema.table`
|
||||
:return: the latest partition array
|
||||
"""
|
||||
|
||||
table_name, schema = self._schema_table(table_name, self.schema)
|
||||
return self.database.db_engine_spec.latest_partition(
|
||||
table_name, schema, self.database
|
||||
@@ -252,6 +270,8 @@ class PrestoTemplateProcessor(BaseTemplateProcessor):
|
||||
table_name=table_name, schema=schema, database=self.database, **kwargs
|
||||
)
|
||||
|
||||
latest_partition = first_latest_partition
|
||||
|
||||
|
||||
class HiveTemplateProcessor(PrestoTemplateProcessor):
|
||||
engine = "hive"
|
||||
|
||||
Reference in New Issue
Block a user