Skip to content

Commit

Permalink
Merge pull request #4 from remerge/merge-upstream-v0.21.11
Browse files Browse the repository at this point in the history
Merge upstream v0.21.11
  • Loading branch information
TLischkaRemerge authored Apr 24, 2023
2 parents 3d58bb4 + e409437 commit 9a7a156
Show file tree
Hide file tree
Showing 182 changed files with 4,367 additions and 1,108 deletions.
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# Change Log

## 0.21.11

- Fix 0.21.10 overwriting 0.21.9

## 0.21.10

- Fix inconsistent results when applying comparisons against overlapping time ranges

## 0.21.9

- Fix filtering for filtered averages in resplit queries for complex inner aggregations

## 0.21.8

- Fix measure re-splitter with filter

## 0.21.7

- Updated Druid SQL driver to be up to date with latest Druid

## 0.21.6

- Better decomposition for time compare

## 0.21.5

- Fix bug when having filter was being swallowed for the timeseries

## 0.21.4

- Fix filtering for filtered averages in resplit queries

## 0.21.3

- Better handle `undefined` in druid groupBys
Expand Down
4 changes: 3 additions & 1 deletion build/datatypes/dataset.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ export declare class Dataset implements Instance<DatasetValue, DatasetJS> {
splitFn(splitFns: Record<string, ComputeFn>, datasetName: string): Dataset;
getReadyExternals(limit?: number): DatasetExternalAlterations;
applyReadyExternals(alterations: DatasetExternalAlterations): Dataset;
sameKeys(other: Dataset): boolean;
getKeyValueForDatum(datum: Datum): string;
getKeyLookup(): Record<string, Datum>;
join(other: Dataset): Dataset;
leftJoin(other: Dataset): Dataset;
fullJoin(other: Dataset, compare: (v1: any, v2: any) => number): Dataset;
fullJoin(other: Dataset): Dataset;
findDatumByAttribute(attribute: string, value: any): Datum | undefined;
getColumns(options?: FlattenOptions): AttributeInfo[];
private _flattenHelper;
Expand Down
75 changes: 34 additions & 41 deletions build/datatypes/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as hasOwnProp from 'has-own-prop';
import { generalEqual, NamedArray, SimpleArray } from 'immutable-class';
import { Expression, ExternalExpression, LiteralExpression } from '../expressions/index';
import { External, TotalContainer } from '../external/baseExternal';
import { deduplicateSort } from '../helper';
import { AttributeInfo } from './attributeInfo';
import { datumHasExternal, valueFromJS, valueToJS } from './common';
import { NumberRange } from './numberRange';
Expand Down Expand Up @@ -803,33 +804,44 @@ var Dataset = (function () {
value.data = data;
return new Dataset(value);
};
Dataset.prototype.sameKeys = function (other) {
return this.keys.join('|') === other.keys.join('|');
};
Dataset.prototype.getKeyValueForDatum = function (datum) {
var keys = this.keys;
if (!keys)
throw new Error('join lhs must have a key (be a product of a split)');
return this.keys.map(function (k) {
var v = datum[k];
if (v && v.start)
v = v.start;
if (v && v.toISOString)
v = v.toISOString();
return v;
}).join('|');
};
Dataset.prototype.getKeyLookup = function () {
var _a = this, data = _a.data, keys = _a.keys;
var thisKey = keys[0];
if (!thisKey)
throw new Error('join lhs must have a key (be a product of a split)');
var mapping = Object.create(null);
for (var i = 0; i < data.length; i++) {
var datum = data[i];
mapping[String(datum[thisKey])] = datum;
mapping[this.getKeyValueForDatum(datum)] = datum;
}
return mapping;
};
Dataset.prototype.join = function (other) {
return this.leftJoin(other);
};
Dataset.prototype.leftJoin = function (other) {
var _this = this;
if (!other || !other.data.length)
return this;
var _a = this, data = _a.data, keys = _a.keys, attributes = _a.attributes;
if (!data.length)
return this;
var thisKey = keys[0];
if (!thisKey)
throw new Error('join lhs must have a key (be a product of a split)');
var otherLookup = other.getKeyLookup();
var newData = data.map(function (datum) {
var otherDatum = otherLookup[String(datum[thisKey])];
var otherDatum = otherLookup[_this.getKeyValueForDatum(datum)];
if (!otherDatum)
return datum;
return joinDatums(datum, otherDatum);
Expand All @@ -840,51 +852,32 @@ var Dataset = (function () {
data: newData
});
};
Dataset.prototype.fullJoin = function (other, compare) {
Dataset.prototype.fullJoin = function (other) {
if (!other || !other.data.length)
return this;
var _a = this, data = _a.data, keys = _a.keys, attributes = _a.attributes;
if (!data.length)
return other;
var thisKey = keys[0];
if (!thisKey)
throw new Error('join lhs must have a key (be a product of a split)');
if (thisKey !== other.keys[0])
if (!this.sameKeys(other)) {
throw new Error('this and other keys must match');
var otherData = other.data;
var dataLength = data.length;
var otherDataLength = otherData.length;
var newData = [];
var i = 0;
var j = 0;
while (i < dataLength || j < otherDataLength) {
if (i < dataLength && j < otherDataLength) {
var nextDatum = data[i];
var nextOtherDatum = otherData[j];
var cmp = compare(nextDatum[thisKey], nextOtherDatum[thisKey]);
if (cmp < 0) {
newData.push(nextDatum);
i++;
}
else if (cmp > 0) {
newData.push(nextOtherDatum);
j++;
}
var myDatumLookup = this.getKeyLookup();
var otherDatumLookup = other.getKeyLookup();
var newData = deduplicateSort(Object.keys(myDatumLookup).concat(Object.keys(otherDatumLookup))).map(function (key) {
var myDatum = myDatumLookup[key];
var otherDatum = otherDatumLookup[key];
if (myDatum) {
if (otherDatum) {
return joinDatums(myDatum, otherDatum);
}
else {
newData.push(joinDatums(nextDatum, nextOtherDatum));
i++;
j++;
return myDatum;
}
}
else if (i === dataLength) {
newData.push(otherData[j]);
j++;
}
else {
newData.push(data[i]);
i++;
return otherDatum;
}
}
});
return new Dataset({
keys: keys,
attributes: AttributeInfo.override(attributes, other.attributes),
Expand Down
4 changes: 3 additions & 1 deletion build/dialect/baseDialect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export declare abstract class SQLDialect {
maybeNamespacedName(name: string): string;
escapeLiteral(name: string): string;
booleanToSQL(bool: boolean): string;
floatDivision(numerator: string, denominator: string): string;
numberOrTimeToSQL(x: number | Date): string;
numberToSQL(num: number): string;
dateToSQLDateString(date: Date): string;
Expand All @@ -28,7 +29,8 @@ export declare abstract class SQLDialect {
abstract timeFloorExpression(operand: string, duration: Duration, timezone: Timezone): string;
abstract timeBucketExpression(operand: string, duration: Duration, timezone: Timezone): string;
abstract timePartExpression(operand: string, part: string, timezone: Timezone): string;
abstract timeShiftExpression(operand: string, duration: Duration, timezone: Timezone): string;
abstract timeShiftExpression(operand: string, duration: Duration, step: int, timezone: Timezone): string;
abstract extractExpression(operand: string, regexp: string): string;
abstract indexOfExpression(str: string, substr: string): string;
logExpression(base: string, operand: string): string;
}
10 changes: 9 additions & 1 deletion build/dialect/baseDialect.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ var SQLDialect = (function () {
SQLDialect.prototype.booleanToSQL = function (bool) {
return ('' + bool).toUpperCase();
};
SQLDialect.prototype.floatDivision = function (numerator, denominator) {
return "(" + numerator + "/" + denominator + ")";
};
SQLDialect.prototype.numberOrTimeToSQL = function (x) {
if (x === null)
return this.nullConstant();
Expand Down Expand Up @@ -94,7 +97,7 @@ var SQLDialect = (function () {
return "(" + a + " IS NOT DISTINCT FROM " + b + ")";
};
SQLDialect.prototype.regexpExpression = function (expression, regexp) {
return "(" + expression + " REGEXP '" + regexp + "')";
return "(" + expression + " REGEXP " + this.escapeLiteral(regexp) + ")";
};
SQLDialect.prototype.inExpression = function (operand, start, end, bounds) {
if (start === end && bounds === '[]')
Expand All @@ -117,6 +120,11 @@ var SQLDialect = (function () {
SQLDialect.prototype.lengthExpression = function (a) {
return "CHAR_LENGTH(" + a + ")";
};
SQLDialect.prototype.logExpression = function (base, operand) {
if (base === String(Math.E))
return "LN(" + operand + ")";
return "LOG(" + base + "," + operand + ")";
};
return SQLDialect;
}());
export { SQLDialect };
9 changes: 5 additions & 4 deletions build/dialect/druidDialect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ import { Duration, Timezone } from 'chronoshift';
import { PlyType } from '../types';
import { SQLDialect } from './baseDialect';
export declare class DruidDialect extends SQLDialect {
static TIME_BUCKETING: Record<string, string>;
static TIME_PART_TO_FUNCTION: Record<string, string>;
static CAST_TO_FUNCTION: Record<string, Record<string, string>>;
constructor();
nullConstant(): string;
dateToSQLDateString(date: Date): string;
floatDivision(numerator: string, denominator: string): string;
constantGroupBy(): string;
timeToSQL(date: Date): string;
concatExpression(a: string, b: string): string;
containsExpression(a: string, b: string): string;
coalesceExpression(a: string, b: string): string;
substrExpression(a: string, position: number, length: number): string;
isNotDistinctFromExpression(a: string, b: string): string;
castExpression(inputType: PlyType, operand: string, cast: string): string;
private operandAsTimestamp;
timeFloorExpression(operand: string, duration: Duration, timezone: Timezone): string;
timeBucketExpression(operand: string, duration: Duration, timezone: Timezone): string;
timePartExpression(operand: string, part: string, timezone: Timezone): string;
timeShiftExpression(operand: string, duration: Duration, timezone: Timezone): string;
timeShiftExpression(operand: string, duration: Duration, step: int, timezone: Timezone): string;
extractExpression(operand: string, regexp: string): string;
regexpExpression(expression: string, regexp: string): string;
indexOfExpression(str: string, substr: string): string;
logExpression(base: string, operand: string): string;
}
Loading

0 comments on commit 9a7a156

Please sign in to comment.