rumbin commented on a change in pull request #8411: Add support for database 
engine SAP Hana
URL: 
https://github.com/apache/incubator-superset/pull/8411#discussion_r337404700
 
 

 ##########
 File path: superset/db_engine_specs/hana.py
 ##########
 @@ -0,0 +1,39 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from datetime import datetime
+
+from superset.db_engine_specs.base import LimitMethod
+from superset.db_engine_specs.postgres import PostgresBaseEngineSpec
+
+
+class HanaEngineSpec(PostgresBaseEngineSpec):
+    engine = "hana"
+    limit_method = LimitMethod.WRAP_SQL
+    force_column_alias_quotes = True
+    max_column_name_length = 30
+
+    _time_grain_functions = {
+        None: '{col}',
+        'P1D': "TO_DATE({col})",
+        'P1M': "TO_DATE(SUBSTRING(to_date({col}),0,7)||'-01')",
+        'P0.25Y': 
"TO_DATE(SUBSTRING(to_date({col}),0,5)||'0'||SUBSTRING(QUARTER(TO_DATE({col}), 
1),7,1)||'-01')",
 
 Review comment:
   It is not at all about anyone's personal needs, I guess, but it may be about 
a misunderstanding on either side of us:
   
   In my understanding the `P0.25Y` time granularity is supposed to yield the 
date of the first month of the corresponding quarter. So, e.g., `2019-Q2` needs 
to be translated to `2019-04-01`. However, your code translates it to 
`2019-02-01` which is simply wrong here.
   
   You may want to play with this development snippet; it may help you 
understand my point of view:
   
   ```
   select
        sub.dt
        ,QUARTER(TO_DATE(sub.dt), 1) as q_date
        ,SUBSTRING(QUARTER(TO_DATE(sub.dt), 1), 7, 1) as q_num
        ,cast(cast(SUBSTRING(QUARTER(TO_DATE(sub.dt), 1), 7, 1) as int) *3 -2 
as text) as month_num
        ,cast(FLOOR((extract(month from sub.dt)-1)/3)*3+1 as text) as month_num2
        ,SUBSTRING(to_date(sub.dt), 0, 
5)||'0'||SUBSTRING(QUARTER(TO_DATE(sub.dt), 1), 7, 1)||'-01' AS 
wrong_quarter_start_date
        ,SUBSTRING(to_date(sub.dt), 0, 5)|| 
lpad(cast((cast(SUBSTRING(QUARTER(TO_DATE(sub.dt), 1), 7, 1) as int)-1)*3 +1 as 
text),2,'0') ||'-01' AS correct_quarter_start_date
        ,SUBSTRING(to_date(sub.dt), 0, 5)|| lpad(cast(FLOOR((extract(month from 
sub.dt)-1)/3)*3+1 as text),2,'0') ||'-01' AS correct_quarter_start_date2
   from (
        select
                to_date('2017-12-28T00:00:00') as dt 
        from dummy
   ) sub
   ```

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to