This is an automated email from the ASF dual-hosted git repository.
michellet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new cd6de3a [Jinja] Make Presto template functions backwards compatible
(#7993)
cd6de3a is described below
commit cd6de3a1d8120d34e290931017764ec3d3965719
Author: Erik Ritter <[email protected]>
AuthorDate: Wed Aug 7 09:35:16 2019 -0700
[Jinja] Make Presto template functions backwards compatible (#7993)
---
docs/sqllab.rst | 2 +-
superset/jinja_context.py | 22 +++++++++++++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/docs/sqllab.rst b/docs/sqllab.rst
index c60123f..c69e584 100644
--- a/docs/sqllab.rst
+++ b/docs/sqllab.rst
@@ -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.
diff --git a/superset/jinja_context.py b/superset/jinja_context.py
index 97b4dfe..2fdcb14 100644
--- a/superset/jinja_context.py
+++ b/superset/jinja_context.py
@@ -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"