Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #50 from michellethomas/mt_cherry_pick_may_merge_f…
Browse files Browse the repository at this point in the history
…ixes

Cherry picking fixes for may merge
  • Loading branch information
michellethomas authored Jun 7, 2018
2 parents c5bbdc5 + f43e460 commit ec0e949
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ describe('AdhocFilterEditPopoverSimpleTabContent', () => {
it('will filter operators for table datasources', () => {
const { wrapper } = setup({ datasource: { type: 'table' } });
expect(wrapper.instance().isOperatorRelevant('regex')).to.be.false;
expect(wrapper.instance().isOperatorRelevant('like')).to.be.true;
expect(wrapper.instance().isOperatorRelevant('LIKE')).to.be.true;
});

it('will filter operators for druid datasources', () => {
const { wrapper } = setup({ datasource: { type: 'druid' } });
expect(wrapper.instance().isOperatorRelevant('regex')).to.be.true;
expect(wrapper.instance().isOperatorRelevant('like')).to.be.false;
expect(wrapper.instance().isOperatorRelevant('LIKE')).to.be.false;
});

it('expands when its multi comparator input field expands', () => {
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/src/components/MetricOption.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const defaultProps = {
};

export default function MetricOption({ metric, openInNewWindow, showFormula, showType, url }) {
const verbose = metric.verbose_name || metric.metric_name;
const verbose = metric.verbose_name || metric.metric_name || metric.label;
const link = url ? <a href={url} target={openInNewWindow ? '_blank' : null}>{verbose}</a> : verbose;
return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/src/explore/AdhocFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const OPERATORS_TO_SQL = {
'<=': '<=',
in: 'in',
'not in': 'not in',
like: 'like',
LIKE: 'like',
};

function translateToSql(adhocMetric, { useSimple } = {}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function translateOperator(operator) {
return 'equals';
} else if (operator === OPERATORS['!=']) {
return 'not equal to';
} else if (operator === OPERATORS.LIKE) {
return 'like';
}
return operator;
}
Expand Down Expand Up @@ -139,8 +141,10 @@ export default class AdhocFilterEditPopoverSimpleTabContent extends React.Compon

handleMultiComparatorInputHeightChange() {
if (this.multiComparatorComponent) {
// eslint-disable-next-line no-underscore-dangle
const multiComparatorDOMNode = this.multiComparatorComponent._selectRef.select.control;
/* eslint-disable no-underscore-dangle */
const multiComparatorDOMNode = this.multiComparatorComponent._selectRef &&
this.multiComparatorComponent._selectRef.select &&
this.multiComparatorComponent._selectRef.select.control;
if (multiComparatorDOMNode) {
if (multiComparatorDOMNode.clientHeight !== this.state.multiComparatorHeight) {
this.props.onHeightChange((
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/explore/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export const OPERATORS = {
'<=': '<=',
in: 'in',
'not in': 'not in',
like: 'like',
LIKE: 'LIKE',
regex: 'regex',
};

export const TABLE_ONLY_OPERATORS = [OPERATORS.like];
export const TABLE_ONLY_OPERATORS = [OPERATORS.LIKE];
export const DRUID_ONLY_OPERATORS = [OPERATORS.regex];
export const HAVING_OPERATORS = [
OPERATORS['=='],
Expand Down
20 changes: 11 additions & 9 deletions superset/assets/src/visualizations/time_table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,28 @@ function viz(slice, payload) {
let leftCell;
const context = { ...fd, metric };
const url = fd.url ? Mustache.render(fd.url, context) : null;
const metricLabel = metric.label || metric;
const metricData = typeof metric === 'object' ? metric : metricMap[metric];
if (!payload.data.is_group_by) {
leftCell = (
<MetricOption metric={metricMap[metric]} url={url} showFormula={false} openInNewWindow />
<MetricOption metric={metricData} url={url} showFormula={false} openInNewWindow />
);
} else {
leftCell = url ? <a href={url} target="_blank">{metric}</a> : metric;
leftCell = url ? <a href={url} target="_blank">{metricLabel}</a> : metric;
}
const row = { metric: leftCell };
fd.column_collection.forEach((column) => {
if (column.colType === 'spark') {
let sparkData;
if (!column.timeRatio) {
sparkData = data.map(d => d[metric]);
sparkData = data.map(d => d[metricLabel]);
} else {
// Period ratio sparkline
sparkData = [];
for (let i = column.timeRatio; i < data.length; i++) {
const prevData = data[i - column.timeRatio][metric];
const prevData = data[i - column.timeRatio][metricLabel];
if (prevData && prevData !== 0) {
sparkData.push(data[i][metric] / prevData);
sparkData.push(data[i][metricLabel] / prevData);
} else {
sparkData.push(null);
}
Expand All @@ -105,7 +107,7 @@ function viz(slice, payload) {
>
{({ onMouseLeave, onMouseMove, tooltipData }) => (
<Sparkline
ariaLabel={`spark-${metric}`}
ariaLabel={`spark-${metricLabel}`}
width={parseInt(column.width, 10) || 300}
height={parseInt(column.height, 10) || 50}
margin={SPARKLINE_MARGIN}
Expand Down Expand Up @@ -135,7 +137,7 @@ function viz(slice, payload) {
),
};
} else {
const recent = reversedData[0][metric];
const recent = reversedData[0][metricLabel];
let v;
let errorMsg;
if (column.colType === 'time') {
Expand All @@ -145,7 +147,7 @@ function viz(slice, payload) {
if (timeLag > totalLag) {
errorMsg = `The time lag set at ${timeLag} exceeds the length of data at ${reversedData.length}. No data available.`;
} else {
v = reversedData[timeLag][metric];
v = reversedData[timeLag][metricLabel];
}
if (column.comparisonType === 'diff') {
v = recent - v;
Expand All @@ -162,7 +164,7 @@ function viz(slice, payload) {
} else if (column.colType === 'avg') {
// Average over the last {timeLag}
v = reversedData
.map((k, i) => i < column.timeLag ? k[metric] : 0)
.map((k, i) => i < column.timeLag ? k[metricLabel] : 0)
.reduce((a, b) => a + b) / column.timeLag;
}
let color;
Expand Down
4 changes: 2 additions & 2 deletions superset/connectors/sqla/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ class TableModelView(DatasourceModelView, DeleteMixin, YamlExportMixin): # noqa
order_columns = ['modified']
add_columns = ['database', 'schema', 'table_name']
edit_columns = [
'table_name', 'sql', 'filter_select_enabled', 'slices',
'table_name', 'sql', 'filter_select_enabled',
'fetch_values_predicate', 'database', 'schema',
'description', 'owner',
'main_dttm_col', 'default_endpoint', 'offset', 'cache_timeout',
'is_sqllab_view', 'template_params',
]
base_filters = [['id', DatasourceFilter, lambda: []]]
show_columns = edit_columns + ['perm']
show_columns = edit_columns + ['perm', 'slices']
related_views = [TableColumnInlineView, SqlMetricInlineView]
base_order = ('changed_on', 'desc')
search_columns = (
Expand Down
65 changes: 65 additions & 0 deletions superset/migrations/versions/c5756bec8b47_time_grain_sqla.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Time grain SQLA
Revision ID: c5756bec8b47
Revises: e502db2af7be
Create Date: 2018-06-04 11:12:59.878742
"""

# revision identifiers, used by Alembic.
revision = 'c5756bec8b47'
down_revision = 'e502db2af7be'

from alembic import op
import json
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Text

from superset import db

Base = declarative_base()


class Slice(Base):
__tablename__ = 'slices'

id = Column(Integer, primary_key=True)
datasource_type = Column(String(200))
slice_name = Column(String(250))
params = Column(Text)


def upgrade():
bind = op.get_bind()
session = db.Session(bind=bind)

for slc in session.query(Slice).all():
try:
params = json.loads(slc.params)

if params.get('time_grain_sqla') == 'Time Column':
params['time_grain_sqla'] = None
slc.params = json.dumps(params, sort_keys=True)
except Exception:
pass

session.commit()
session.close()


def downgrade():
bind = op.get_bind()
session = db.Session(bind=bind)

for slc in session.query(Slice).all():
try:
params = json.loads(slc.params)

if params.get('time_grain_sqla') is None:
params['time_grain_sqla'] = 'Time Column'
slc.params = json.dumps(params, sort_keys=True)
except Exception:
pass

session.commit()
session.close()

0 comments on commit ec0e949

Please sign in to comment.