superset2.0.0 支持MaxCompute 时间颗粒
2024-10-21 17:33:13
编译的时候需要在superset/superset/db_engine_specs以下路径增加一个 odps.py的文件
# 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 typing import Any, Dict, List, Optional, Tuple
from superset.db_engine_specs.base import BaseEngineSpec
from superset.utils import core as utils
class ODPSEngineSpec(BaseEngineSpec):
engine = "odps"
engine_name = "MaxCompute"
_time_grain_expressions = {
None: "{col}",
"PT1S": "CAST({col} as DATETIME)",
"PT1M": "DATETRUNC(CAST({col} as DATETIME),'MI')",
"PT1H": "DATETRUNC(CAST({col} as DATETIME),'HH')",
"P1D": "DATE({col})",
"P1W": "DATETRUNC(CAST({col} as DATETIME),'w')",
"P1M": "DATETRUNC(CAST({col} as DATETIME),'mon')",
"P3M": "DATETRUNC(CAST({col} as DATETIME),'q')",
"P1Y": "DATETRUNC(CAST({col} as DATETIME),'year')",
}
@classmethod
def convert_dttm(
cls, target_type: str, dttm: datetime, db_extra: Optional[Dict[str, Any]] = None
) -> Optional[str]:
tt = target_type.upper()
if tt == utils.TemporalType.DATE:
return f"TO_DATE('{dttm.date().isoformat()}', 'yyyy-mm-dd')"
if tt == utils.TemporalType.DATETIME:
datetime_formatted = dttm.isoformat(sep=" ", timespec="microseconds")
return f"""TO_DATE('{datetime_formatted}', 'yyyy-mm-dd hh:mi:ss.ff3')"""
return None
@classmethod
def epoch_to_dttm(cls) -> str:
return "from_unixtime({col})"
最新文章
- Win7 登入提示临时漫游档案
- [译]rabbitmq 2.2 Building from the bottom: queues
- IBatis.Net 批量插入数据
- gulp 使用mailgun服务器发送邮件
- 第二百七十二、三天 how can I 坚持
- Python基础教程之List对象 转
- Swift Swift语言Storyboard教程:第二部
- 执行 npm run update-webdriver 提示文件不能获取错误
- vue+vue-router+vuex实战
- JMeter进行一次简单的压力测试
- Django中URL有关
- Nginx 学习笔记(四)nginx-module-vts模块
- 动态规划之132 Palindrome Partitioning II
- Spring设置动态定时任务
- MVC 学习(一)Linq to Entities 简单Demo
- jquery 鼠标事件汇总
- panel内嵌程序窗体
- php 传变量到 js 文件
- lua调用c++函数返回值作用
- jvm系列 (一) ---jvm内存区域与溢出
热门文章
- Vue框架整理:computed计算属性设置与缓存
- PostgreSQL事务隔离级别
- ImGui窗口标题栏的高度
- DataTransfer.setDragImage()自定义拖拽图像遇到的坑
- ImportError: cannot import name 'six' from 'django.utils'的解决办法
- 客户端发送信息给服务器以及服务器接收客户端发来的信息(socket)
- java字段值为null,不返回该字段
- 2022-05-06内部群每日三题-清辉PMP
- The table‘xxxx’is full
- java之路总结