Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kylin datasource. #605

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 7 additions & 107 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,12 @@
Caravel
=========
<img src="http://i.imgur.com/H0Kyvyi.jpg" style="border-radius: 20px; box-shadow:5px 5px 5px gray;" alt="Caravel" width="500"/>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope.

* 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
29 changes: 26 additions & 3 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ def sql_url(self):
def sql_link(self):
return '<a href="{}">SQL</a>'.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):

Expand Down Expand Up @@ -601,23 +607,40 @@ 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

if is_timeseries:
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),
Expand Down
8 changes: 7 additions & 1 deletion caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down