本文整理匯總了TypeScript中plywood.AttributeInfo.fromJSs方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript AttributeInfo.fromJSs方法的具體用法?TypeScript AttributeInfo.fromJSs怎麽用?TypeScript AttributeInfo.fromJSs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類plywood.AttributeInfo
的用法示例。
在下文中一共展示了AttributeInfo.fromJSs方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('adds new dimensions', () => {
var columns: any = [
{ "name": "__time", "type": "TIME" },
{ "name": "added", "makerAction": { "action": "sum", "expression": { "name": "added", "op": "ref" }}, "type": "NUMBER", "unsplitable": true },
{ "name": "count", "makerAction": { "action": "count"}, "type": "NUMBER", "unsplitable": true },
{ "name": "delta_hist", "special": "histogram", "type": "NUMBER" },
{ "name": "page", "type": "STRING" },
{ "name": "page_unique", "special": "unique", "type": "STRING" }
];
var dataCube1 = dataCube.addAttributes(AttributeInfo.fromJSs(columns));
expect(dataCube1.toJS().dimensions).to.deep.equal([
{
"kind": "time",
"name": "__time",
"title": "Time",
"formula": "$__time"
},
{
"kind": "string",
"name": "page",
"title": "Page",
"formula": "$page"
}
]);
columns.push({ "name": "channel", "type": "STRING" });
var dataCube2 = dataCube1.addAttributes(AttributeInfo.fromJSs(columns));
expect(dataCube2.toJS().dimensions).to.deep.equal([
{
"kind": "time",
"name": "__time",
"title": "Time",
"formula": "$__time"
},
{
"kind": "string",
"name": "page",
"title": "Page",
"formula": "$page"
},
{
"kind": "string",
"name": "channel",
"title": "Channel",
"formula": "$channel"
}
]);
});
示例2: deduceAttributes
/**
* This function tries to deduce the structure of the dataSource based on the dimensions and measures defined within.
* It should only be used when for some reason introspection if not available.
* @param dataSource
* @returns {Attributes}
*/
function deduceAttributes(dataSource: DataSource): Attributes {
var attributeJSs: AttributeJSs = [];
dataSource.dimensions.forEach((dimension) => {
// ToDo: fix this.
attributeJSs.push({ name: dimension.name, type: 'STRING' });
});
dataSource.measures.forEach((measure) => {
var expression = measure.expression;
var references = getReferences(expression);
var countDistinctReferences = getCountDistinctReferences(expression);
for (var reference of references) {
if (reference === 'main') continue;
if (countDistinctReferences.indexOf(reference) !== -1) {
attributeJSs.push({ name: reference, special: 'unique' });
} else {
attributeJSs.push({ name: reference, type: 'NUMBER' });
}
}
});
var attributes = AttributeInfo.fromJSs(attributeJSs);
if (dataSource.options['attributeOverrides']) {
attributes = AttributeInfo.applyOverrides(attributes, dataSource.options['attributeOverrides']);
}
return attributes;
}
示例3: deduceAttributes
/**
* This function tries to deduce the structure of the dataSource based on the dimensions and measures defined within.
* It should only be used when, for some reason, introspection if not available.
* @param dataSource
* @returns {Attributes}
*/
function deduceAttributes(dataSource: DataSource): Attributes {
var attributeJSs: AttributeJSs = [];
var timeAttribute = dataSource.timeAttribute;
if (timeAttribute) {
attributeJSs.push({ name: timeAttribute.name, type: 'TIME' });
}
dataSource.dimensions.forEach((dimension) => {
var expression = dimension.expression;
if (expression.equals(timeAttribute)) return;
var references = getReferences(expression);
for (var reference of references) {
if (reference === 'main') continue;
attributeJSs.push({ name: reference, type: 'STRING' });
}
});
dataSource.measures.forEach((measure) => {
var expression = measure.expression;
var references = getReferences(expression);
var countDistinctReferences = getCountDistinctReferences(expression);
for (var reference of references) {
if (reference === 'main') continue;
if (countDistinctReferences.indexOf(reference) !== -1) {
attributeJSs.push({ name: reference, special: 'unique' });
} else {
attributeJSs.push({ name: reference, type: 'NUMBER' });
}
}
});
var attributes = AttributeInfo.fromJSs(attributeJSs);
if (dataSource.attributeOverrides.length) {
attributes = AttributeInfo.override(attributes, dataSource.attributeOverrides);
}
return attributes;
}
示例4: it
it("works with existing dimension", () => {
var attributes1 = AttributeInfo.fromJSs([
{ name: '__time', type: 'TIME' },
{ name: 'added', type: 'NUMBER' },
{ name: 'added!!!', type: 'NUMBER' },
{ name: 'deleted', type: 'NUMBER' }
]);
var dataSourceWithDim = DataSource.fromJS({
name: 'wiki',
title: 'Wiki',
engine: 'druid',
source: 'wiki',
subsetFilter: null,
introspection: 'autofill-all',
defaultTimezone: 'Etc/UTC',
defaultFilter: { op: 'literal', value: true },
refreshRule: {
refresh: "PT1M",
rule: "fixed"
},
dimensions: [
{
name: 'added',
expression: '$added'
},
{
name: 'added_',
expression: '${added!!!}'
}
]
});
var dataSource = dataSourceWithDim.addAttributes(attributes1);
expect(dataSource.toJS().measures.map(m => m.name)).to.deep.equal(['deleted']);
});