Skip to content

Commit

Permalink
Adding support for Druid post aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Feb 11, 2016
1 parent e39d6db commit 86e354f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
32 changes: 32 additions & 0 deletions panoramix/migrations/versions/b4a0abe21630_post_aggs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""post_aggs
Revision ID: b4a0abe21630
Revises: 430039611635
Create Date: 2016-02-10 15:16:58.953042
"""

# revision identifiers, used by Alembic.
revision = 'b4a0abe21630'
down_revision = '430039611635'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql


def upgrade():
op.create_table('post_aggregators',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=512), nullable=True),
sa.Column('verbose_name', sa.String(length=1024), nullable=True),
sa.Column('datasource_name', sa.String(length=250), nullable=True),
sa.Column('json', sa.Text(), nullable=True),
sa.Column('description', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['datasource_name'], ['datasources.datasource_name'], ),
sa.PrimaryKeyConstraint('id')
)


def downgrade():
op.drop_table('post_aggregators')
13 changes: 13 additions & 0 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,3 +1170,16 @@ def generate_metrics(self):
if not m:
session.add(metric)
session.commit()


class DruidPostAggregator(Model):
__tablename__ = 'post_aggregators'
id = Column(Integer, primary_key=True)
name = Column(String(512))
verbose_name = Column(String(1024))
datasource_name = Column(
String(250),
ForeignKey('datasources.datasource_name'))
datasource = relationship('DruidDatasource', backref='post_aggregators')
json = Column(Text)
description = Column(Text)
19 changes: 19 additions & 0 deletions panoramix/static/widgets/viz_helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
px.registerViz('helloworld', function(slice) {

function refresh() {
$('#code').attr('rows', '15')
$.getJSON(slice.jsonEndpoint(), function(payload) {
slice.container.html(
'<h1>HELLOW '+ payload.form_data.username +' !!!</h1>');
console.log(payload);
slice.done();
})
.fail(function(xhr) {
slice.error(xhr.responseText);
});
};
return {
render: refresh,
resize: refresh,
};
});
18 changes: 17 additions & 1 deletion panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ class DruidMetricInlineView(CompactCRUDMixin, PanoramixModelView):
appbuilder.add_view_no_menu(DruidMetricInlineView)


class DruidPostAggregatorInlineView(CompactCRUDMixin, PanoramixModelView):
datamodel = SQLAInterface(models.DruidPostAggregator)
list_columns = ['name', 'verbose_name']
edit_columns = [
'name', 'description', 'verbose_name', 'datasource', 'json']
add_columns = edit_columns
page_size = 500
validators_columns = {
'json': [validate_json],
}
appbuilder.add_view_no_menu(DruidPostAggregatorInlineView)


class DatabaseView(PanoramixModelView, DeleteMixin):
datamodel = SQLAInterface(models.Database)
list_columns = ['database_name', 'sql_link', 'created_by', 'changed_on_']
Expand Down Expand Up @@ -284,10 +297,13 @@ class DruidDatasourceModelView(PanoramixModelView, DeleteMixin):
'created_by', 'created_on',
'changed_by_', 'changed_on',
'offset']
related_views = [DruidColumnInlineView, DruidMetricInlineView]
related_views = [
DruidColumnInlineView, DruidMetricInlineView,
DruidPostAggregatorInlineView]
edit_columns = [
'datasource_name', 'cluster', 'description', 'owner',
'is_featured', 'is_hidden', 'default_endpoint', 'offset']
add_columns = edit_columns
page_size = 500
base_order = ('datasource_name', 'asc')
description_columns = {
Expand Down

0 comments on commit 86e354f

Please sign in to comment.