Skip to content

Commit

Permalink
pure fallback works
Browse files Browse the repository at this point in the history
  • Loading branch information
vogievetsky committed May 28, 2016
1 parent 8ea15a9 commit f480415
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ For updates follow [@implydata](https://twitter.com/implydata) on Twitter.

- DruidExternal: Fix bug where `$blah / 10` did not work in split
- DruidExternal: Fix bug where `1 + $blah` did not cast to number
- DruidExternal: Pure `.fallback()` now works

## 0.10.26

Expand Down
4 changes: 4 additions & 0 deletions src/actions/isAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ module Plywood {
return new InAction({ expression: this.expression })
}

if (prevAction instanceof FallbackAction && prevAction.expression.isOp('literal') && this.expression.isOp('literal') && !prevAction.expression.equals(this.expression)) {
return this;
}

return null;
}

Expand Down
15 changes: 14 additions & 1 deletion src/external/druidExternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ module Plywood {

if (action instanceof ExtractAction) {
// retainMissingValue === false is not supported in old druid nor is replaceMissingValueWith in regex extractionFn
// we want to use a js function if we are using an old version of druid and want to use this functionality
// we want to use a js function if we are using an old version of Druid
if (this.versionBefore('0.9.0') && (retainMissingValue === false || replaceMissingValueWith !== null)) {
return this.actionToJavaScriptExtractionFn(action);
}
Expand Down Expand Up @@ -1276,6 +1276,19 @@ module Plywood {
return this.actionToJavaScriptExtractionFn(action);
}

if (action instanceof FallbackAction && action.expression.isOp('literal')) {
return {
type: "lookup",
retainMissingValue: true,
lookup: {
type: "map",
map: {
"": action.getLiteralValue()
}
}
};
}

throw new Error(`can not covert ${action} to extractionFn`);
}

Expand Down
18 changes: 18 additions & 0 deletions test/functional/crossFunctional.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,24 @@ describe("Cross Functional", function() {
.limit(20)
}));

it('works with STRING split .fallback() no match', equalityTest({
executorNames: ['druid', 'mysql', 'postgres'],
expression: $('wiki').split('$cityName.fallback("NoCity")', 'CityFallback')
.apply('TotalEdits', '$wiki.sum($count)')
.apply('TotalAdded', '$wiki.sum($added)')
.sort('$TotalAdded', 'descending')
.limit(20)
}));

it('works with STRING split .fallback() with match', equalityTest({
executorNames: ['druid', 'mysql', 'postgres'],
expression: $('wiki').split('$cityName.fallback("Bucharest")', 'CityFallback')
.apply('TotalEdits', '$wiki.sum($count)')
.apply('TotalAdded', '$wiki.sum($added)')
.sort('$TotalAdded', 'descending')
.limit(20)
}));

it('works with NUMBER split (numberBucket) (sort on split)', equalityTest({
executorNames: ['druid', 'mysql', 'postgres'],
expression: $('wiki').split($("commentLength").numberBucket(10), 'CommentLength10')
Expand Down
12 changes: 12 additions & 0 deletions test/overall/simplify.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,18 @@ describe("Simplify", () => {
simplifiesTo(ex1, ex2);
});

it('kills impossible fallback', () => {
var ex1 = $('color').fallback('NoColor').is('D');
var ex2 = $('color').is('D');;
simplifiesTo(ex1, ex2);
});

it('leaves possible fallback', () => {
var ex1 = $('color').fallback('D').is('D');
var ex2 = $('color').fallback('D').is('D');
simplifiesTo(ex1, ex2);
});

});


Expand Down
34 changes: 34 additions & 0 deletions test/simulate/simulateDruid.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,40 @@ describe("simulate Druid", () => {
});
});

it("works on fancy filter .fallback().is() [impossible]", () => {
var ex = ply()
.apply("diamonds", $('diamonds').filter("$color.fallback('NoColor') == 'D'"))
.apply('Count', '$diamonds.count()');

expect(ex.simulateQueryPlan(context)[0].filter).to.deep.equal({
"dimension": "color",
"type": "selector",
"value": "D"
});
});

it("works on fancy filter .fallback().is() [possible]", () => {
var ex = ply()
.apply("diamonds", $('diamonds').filter("$color.fallback('D') == 'D'"))
.apply('Count', '$diamonds.count()');

expect(ex.simulateQueryPlan(context)[0].filter).to.deep.equal({
"dimension": "color",
"extractionFn": {
"lookup": {
"map": {
"": "D"
},
"type": "map"
},
"retainMissingValue": true,
"type": "lookup"
},
"type": "extraction",
"value": "D"
});
});

it("works on fancy filter .extract().is()", () => {
var ex = ply()
.apply("diamonds", $('diamonds').filter("$color.extract('^(.)') == 'D'"))
Expand Down

0 comments on commit f480415

Please sign in to comment.