From fa2b01c1c11a03839b435ce03f5dd554345a5ed6 Mon Sep 17 00:00:00 2001 From: rocky1001 Date: Mon, 6 Jun 2016 16:10:08 +0800 Subject: [PATCH 1/2] modified for kylin datasource. --- caravel/models.py | 29 ++++++++++++++++++++++++++--- caravel/viz.py | 8 +++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/caravel/models.py b/caravel/models.py index 619682a12be4a..1b9bd589234fd 100644 --- a/caravel/models.py +++ b/caravel/models.py @@ -430,6 +430,12 @@ def sql_url(self): def sql_link(self): return 'SQL'.format(self.sql_url) + def get_timestamp_label_for_db(self): + if self.sqlalchemy_uri.startswith('kylin'): + return "_timestamp" + else: + return "timestamp" + class SqlaTable(Model, Queryable, AuditMixinNullable): @@ -601,15 +607,18 @@ def query( # sqla metrics_exprs = [] if granularity: + + timestamp_label = self.database.get_timestamp_label_for_db() + dttm_expr = cols[granularity].expression or granularity - timestamp = literal_column(dttm_expr).label('timestamp') + timestamp = literal_column(dttm_expr).label(timestamp_label) # Transforming time grain into an expression based on configuration time_grain_sqla = extras.get('time_grain_sqla') if time_grain_sqla: udf = self.database.grains_dict().get(time_grain_sqla, '{col}') timestamp_grain = literal_column( - udf.function.format(col=dttm_expr)).label('timestamp') + udf.function.format(col=dttm_expr)).label(timestamp_label) else: timestamp_grain = timestamp @@ -617,7 +626,21 @@ def query( # sqla select_exprs += [timestamp_grain] groupby_exprs += [timestamp_grain] - tf = '%Y-%m-%d %H:%M:%S.%f' + # UGLY: I guess correct way is to delegate on SQLAlchemy dialect + # UPDATE: Datetime depends on each dialect and I haven't found an easy way to manage + # Maybe we can allow user to define its custome format at Database definition + def get_dtformat(type): + if type == 'SMALLDATETIME' or type == 'DATETIME': + return '%Y-%m-%d %H:%M:%S' + if type == 'DATE': + return '%Y-%m-%d' + if type == 'TIME': + return '%H:%M:%S' + return '%Y-%m-%d %H:%M:%S.%f' + + tf = get_dtformat(cols[granularity].type or 'DATE') + + # tf = '%Y-%m-%d %H:%M:%S.%f' time_filter = [ timestamp >= from_dttm.strftime(tf), timestamp <= to_dttm.strftime(tf), diff --git a/caravel/viz.py b/caravel/viz.py index 70504f6f3042d..bef54a8b8a282 100644 --- a/caravel/viz.py +++ b/caravel/viz.py @@ -864,8 +864,14 @@ def get_df(self, query_obj=None): if form_data.get("granularity") == "all": raise Exception("Pick a time granularity for your time series") + sqlalchemy_uri = self.datasource.database.sqlalchemy_uri + if sqlalchemy_uri.startswith('kylin'): + df_index = '_timestamp' + else: + df_index = 'timestamp' + df = df.pivot_table( - index="timestamp", + index=df_index, columns=form_data.get('groupby'), values=form_data.get('metrics')) From de1aa56c61de3d3366ecb12021b7ebf36df77769 Mon Sep 17 00:00:00 2001 From: rocky1001 Date: Mon, 13 Jun 2016 10:53:26 +0800 Subject: [PATCH 2/2] update readme add usage info --- README.md | 114 ++++-------------------------------------------------- 1 file changed, 7 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index e398dff8a9067..1270a34446669 100644 --- a/README.md +++ b/README.md @@ -1,112 +1,12 @@ Caravel ========= -Caravel + + * forked from https://github.com/airbnb/caravel -[![Build Status](https://travis-ci.org/airbnb/caravel.svg?branch=master)](https://travis-ci.org/airbnb/caravel) -[![PyPI version](https://badge.fury.io/py/caravel.svg)](https://badge.fury.io/py/caravel) -[![Coverage Status](https://coveralls.io/repos/airbnb/caravel/badge.svg?branch=master&service=github)](https://coveralls.io/github/airbnb/caravel?branch=master) -[![Code Health](https://landscape.io/github/airbnb/caravel/master/landscape.svg?style=flat)](https://landscape.io/github/airbnb/caravel/master) -[![Requirements Status](https://requires.io/github/airbnb/caravel/requirements.svg?branch=master)](https://requires.io/github/airbnb/caravel/requirements/?branch=master) -[![Join the chat at https://gitter.im/airbnb/caravel](https://badges.gitter.im/airbnb/caravel.svg)](https://gitter.im/airbnb/caravel?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Documentation](https://img.shields.io/badge/docs-airbnb.io-blue.svg)](http://airbnb.io/caravel/) +Usage +------- -Caravel is a data exploration platform designed to be visual, intuitive -and interactive. +refer the blog below: -[this project used to be named **Panoramix**] - - -Video - Introduction to Caravel ---------------------------------- -[![Caravel - ](http://img.youtube.com/vi/3Txm_nj_R7M/0.jpg)](http://www.youtube.com/watch?v=3Txm_nj_R7M) - -Screenshots ------------- -![img](http://i.imgur.com/JRbTnTx.png) -![img](http://i.imgur.com/4wRtxwb.png) - -Caravel ---------- -Caravel's main goal is to make it easy to slice, dice and visualize data. -It empowers users to perform **analytics at the speed of thought**. - -Caravel provides: -* A quick way to intuitively visualize datasets by allowing users to create - and share interactive dashboards -* A rich set of visualizations to analyze your data, as well as a flexible - way to extend the capabilities -* An extensible, high granularity security model allowing intricate rules - on who can access which features, and integration with major - authentication providers (database, OpenID, LDAP, OAuth & REMOTE_USER - through Flask AppBuiler) -* A simple semantic layer, allowing to control how data sources are - displayed in the UI, by defining which fields should show up in - which dropdown and which aggregation and function (metrics) are - made available to the user -* Deep integration with Druid allows for Caravel to stay blazing fast while - slicing and dicing large, realtime datasets - - -Database Support ----------------- - -Caravel was originally designed on top of Druid.io, but quickly broadened -its scope to support other databases through the use of SQLAlchemy, a Python -ORM that is compatible with -[most common databases](http://docs.sqlalchemy.org/en/rel_1_0/core/engines.html). - - -What is Druid? -------------- -From their website at http://druid.io - -*Druid is an open-source analytics data store designed for -business intelligence (OLAP) queries on event data. Druid provides low -latency (real-time) data ingestion, flexible data exploration, -and fast data aggregation. Existing Druid deployments have scaled to -trillions of events and petabytes of data. Druid is best used to -power analytic dashboards and applications.* - - -Installation & Configuration ----------------------------- - -[See in the documentation](http://airbnb.io/caravel/installation.html) - - -More screenshots ----------------- - -![img](http://i.imgur.com/MAFZTtU.png) -![img](http://i.imgur.com/xcy1QjN.png) -![img](http://i.imgur.com/RWqA8ly.png) -![img](http://i.imgur.com/D2kZL7q.png) -![img](http://i.imgur.com/0UPTK61.png) -![img](http://i.imgur.com/ahHoCuS.png) - - -Resources -------------- -* [Caravel Google Group](https://groups.google.com/forum/#!forum/airbnb_caravel) -* [Gitter (live chat) Channel](https://gitter.im/airbnb/caravel) -* [Docker image 1](https://hub.docker.com/r/kochalex/caravel/) - [Docker image 2](https://hub.docker.com/r/amancevice/caravel/) (community contributed) -* [Slides from Strata (March 2016)](https://drive.google.com/open?id=0B5PVE0gzO81oOVJkdF9aNkJMSmM) - - -Tip of the Hat --------------- - -Caravel would not be possible without these great frameworks / libs - -* Flask App Builder - Allowing us to focus on building the app quickly while -getting the foundation for free -* The Flask ecosystem - Simply amazing. So much Plug, easy play. -* NVD3 - One of the best charting libraries out there -* Much more, check out the `install_requires` section in the [setup.py](https://github.com/airbnb/caravel/blob/master/setup.py) file! - - -Contributing ------------- - -Interested in contributing? Casual hacking? Check out [Contributing.MD](https://github.com/airbnb/caravel/blob/master/CONTRIBUTING.md) + * http://lxw1234.com/archives/2016/06/681.htm + * http://lxw1234.com/archives/2016/06/688.htm