You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/04/21 16:55:37 UTC

[GitHub] [incubator-superset] agrawaldevesh commented on a change in pull request #7131: Make timestamp expression native SQLAlchemy element

agrawaldevesh commented on a change in pull request #7131: Make timestamp expression native SQLAlchemy element
URL: https://github.com/apache/incubator-superset/pull/7131#discussion_r277174784
 
 

 ##########
 File path: superset/db_engine_specs.py
 ##########
 @@ -83,6 +85,24 @@
 }
 
 
+class TimestampExpression(ColumnClause):
+    def __init__(self, expr: str, col: ColumnClause, **kwargs):
+        """Sqlalchemy class that can be can be used to render native column elements
+        respeting engine-specific quoting rules as part of a string-based expression.
+
+        :param expr: Sql expression with '{col}' denoting the locations where the col
+        object will be rendered.
+        :param col: the target column
+        """
+        super().__init__(expr, **kwargs)
+        self.col = col
+
+
+@compiles(TimestampExpression)
+def compile_timegrain_expression(element: TimestampExpression, compiler, **kw):
+    return element.name.replace('{col}', compiler.process(element.col, **kw))
 
 Review comment:
   What is "name" of a ColumnClause ? 
   
   Do we need to pass this further via the compiler ? Is this supposed to return a string back or is it supposed to return some sqlalchemy struct, and so we might have to do:
   
   ```
   compiler.process(element.name.replace('{col}', compiler.process(element.col, **kw)))
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org