本文整理汇总了TypeScript中plywood.Expression类的典型用法代码示例。如果您正苦于以下问题:TypeScript Expression类的具体用法?TypeScript Expression怎么用?TypeScript Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(parameters: DimensionValue) {
var name = parameters.name;
verifyUrlSafeName(name);
this.name = name;
this.title = parameters.title || makeTitle(name);
var formula = parameters.formula || $(name).toString();
this.formula = formula;
this.expression = Expression.parse(formula);
var kind = parameters.kind || typeToKind(this.expression.type) || 'string';
this.kind = kind;
if (kind === 'string' && isGeo(name)) {
this.className = 'string-geo';
} else {
this.className = kind;
}
if (parameters.url) {
if (typeof parameters.url !== 'string') {
throw new Error(`unsupported url: ${parameters.url}: only strings are supported`);
}
this.url = parameters.url;
}
if (parameters.granularities) {
if (parameters.granularities.length !== 5) throw new Error('there must be exactly 5 granularities');
this.granularities = parameters.granularities;
}
if (parameters.bucketedBy) this.bucketedBy = parameters.bucketedBy;
if (parameters.bucketingStrategy) this.bucketingStrategy = parameters.bucketingStrategy;
if (parameters.sortStrategy) this.sortStrategy = parameters.sortStrategy;
}
示例2: return
return (ex: Expression, env: Environment = {}) => {
return Qajax({
method: "POST",
url: url + '?by=' + getSplitsDescription(ex),
data: {
version: version,
dataCube: name,
expression: ex.toJS(),
timezone: env ? env.timezone : null
}
})
.then(Qajax.filterSuccess)
.then(Qajax.toJSON)
.then(
(res) => {
return Dataset.fromJS(res.result);
},
(xhr: XMLHttpRequest): Dataset => {
if (!xhr) return null; // This is only here to stop TS complaining
var jsonError = JSON.parse(xhr.responseText);
if (jsonError.action === 'reload') reload();
throw new Error(jsonError.message || jsonError.error);
}
);
};
示例3: fromJS
static fromJS(parameters: SplitCombineJS, context?: SplitCombineContext): SplitCombine {
if (typeof parameters === 'string') {
if (!context) throw new Error('must have context for string split');
var dimension = context.dimensions.find(d => d.name === parameters);
if (!dimension) throw new Error(`can not find dimension ${parameters}`);
return new SplitCombine({
expression: dimension.expression,
bucketAction: null,
sortAction: null,
limitAction: null
});
} else {
var value: SplitCombineValue = {
expression: Expression.fromJSLoose(parameters.expression),
bucketAction: null,
sortAction: null,
limitAction: null
};
if (parameters.bucketAction) value.bucketAction = Action.fromJS(parameters.bucketAction);
if (parameters.sortAction) value.sortAction = SortAction.fromJS(parameters.sortAction);
if (parameters.limitAction) value.limitAction = LimitAction.fromJS(parameters.limitAction);
return new SplitCombine(value);
}
}
示例4: fromJS
static fromJS(parameters: DimensionJS): Dimension {
var value: DimensionValue = {
name: parameters.name,
title: parameters.title,
expression: parameters.expression ? Expression.fromJSLoose(parameters.expression) : null,
kind: parameters.kind || typeToKind((parameters as any).type),
url: parameters.url
};
var granularities = parameters.granularities;
if (granularities) {
if (!Array.isArray(granularities) || granularities.length !== 5) {
throw new Error(`must have list of 5 granularities in dimension '${parameters.name}'`);
}
var runningActionType: string = null;
value.granularities = granularities.map((g) => {
var granularity = granularityFromJS(g);
if (runningActionType === null) runningActionType = granularity.action;
if (granularity.action !== runningActionType) throw new Error("granularities must have the same type of actions");
return granularity;
});
}
return new Dimension(value);
}
示例5: createJSONServer
createJSONServer(port, (parameters: JSONParameters, res: any) => {
var { sql } = parameters;
try {
var sqlParse = Expression.parseSQL(sql);
} catch (e) {
res.status(400).send({ error: e.message });
return;
}
if (sqlParse.verb && sqlParse.verb !== 'SELECT') { // DESCRIBE + SHOW get re-written
res.status(400).send({ error: `Unsupported SQL verb ${sqlParse.verb} must be SELECT, DESCRIBE, SHOW, or a raw expression` });
}
executeSQLParse(sqlParse, context, timezone)
.then((value: PlywoodValue) => {
if (Dataset.isDataset(value)) {
res.json({
result: value.toJS()
});
} else {
res.json({
result: value
});
}
})
.fail((e) => {
res.status(400).send({ error: e.message });
})
.done();
});
示例6: fromJS
static fromJS(parameters: DimensionJS): Dimension {
return new Dimension({
name: parameters.name,
title: parameters.title,
expression: parameters.expression ? Expression.fromJSLoose(parameters.expression) : null,
kind: parameters.kind || typeToKind((parameters as any).type)
});
}
示例7: fromJS
static fromJS(parameters: DimensionJS): Dimension {
return new Dimension({
name: parameters.name,
title: parameters.title,
expression: parameters.expression ? Expression.fromJSLoose(parameters.expression) : null,
type: parameters.type || 'STRING',
sortOn: parameters.sortOn || null
});
}
示例8: getReferences
function getReferences(ex: Expression): string[] {
var references: string[] = [];
ex.forEach((ex: Expression) => {
if (ex instanceof RefExpression) {
references.push(ex.name);
}
});
return references;
}
示例9: upperCaseRefs
function upperCaseRefs(expression: Expression): Expression {
return expression.substitute((ex) => {
if (ex instanceof RefExpression) {
var v = ex.valueOf();
v.name = v.name.toUpperCase();
return new RefExpression(v);
}
return null;
})
}
示例10: getSplitsDescription
function getSplitsDescription(ex: Expression): string {
var splits: string[] = [];
ex.forEach((ex) => {
if (ex instanceof ChainExpression) {
ex.actions.forEach((action) => {
if (action.action === 'split') splits.push(action.expression.toString());
});
}
});
return splits.join(';');
}
示例11: equals
public equals(other: Dimension): boolean {
return Dimension.isDimension(other) &&
this.name === other.name &&
this.title === other.title &&
this.expression.equals(other.expression) &&
this.kind === other.kind;
}
示例12: toJS
public toJS(): DimensionJS {
return {
name: this.name,
title: this.title,
expression: this.expression.toJS(),
kind: this.kind
};
}
示例13: equals
public equals(other: Dimension): boolean {
return Dimension.isDimension(other) &&
this.name === other.name &&
this.title === other.title &&
this.expression.equals(other.expression) &&
this.type === other.type &&
this.sortOn === other.sortOn;
}
示例14: toJS
public toJS(): SplitCombineJS {
var js: SplitCombineJSFull = {
expression: this.expression.toJS()
};
if (this.bucketAction) js.bucketAction = this.bucketAction.toJS();
if (this.sortAction) js.sortAction = this.sortAction.toJS();
if (this.limitAction) js.limitAction = this.limitAction.toJS();
return js;
}
示例15: equals
public equals(other: Dimension): boolean {
return Dimension.isDimension(other) &&
this.name === other.name &&
this.title === other.title &&
this.expression.equals(other.expression) &&
this.kind === other.kind &&
this.url === other.url &&
immutableArraysEqual(this.granularities, other.granularities);
}