• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript plywood.Expression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中plywood.Expression的典型用法代码示例。如果您正苦于以下问题:TypeScript Expression类的具体用法?TypeScript Expression怎么用?TypeScript Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Expression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
  }
开发者ID:djfwan,项目名称:pivot,代码行数:33,代码来源:dimension.ts


示例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);
       }
     );
 };
开发者ID:djfwan,项目名称:pivot,代码行数:25,代码来源:ajax.ts


示例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);
    }
  }
开发者ID:RaviNK,项目名称:pivot,代码行数:25,代码来源:split-combine.ts


示例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);
  }
开发者ID:gerencio,项目名称:pivot,代码行数:25,代码来源:dimension.ts


示例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();
  });
开发者ID:waltonseymour,项目名称:plyql,代码行数:31,代码来源:plyql-json-server.ts


示例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)
   });
 }
开发者ID:coconutpalm,项目名称:pivot,代码行数:8,代码来源:dimension.ts


示例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
   });
 }
开发者ID:Ghostubborn,项目名称:pivot,代码行数:9,代码来源:dimension.ts


示例8: getReferences

function getReferences(ex: Expression): string[] {
  var references: string[] = [];
  ex.forEach((ex: Expression) => {
    if (ex instanceof RefExpression) {
      references.push(ex.name);
    }
  });
  return references;
}
开发者ID:coconutpalm,项目名称:pivot,代码行数:9,代码来源:executor.ts


示例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;
  })
}
开发者ID:baeeq,项目名称:plyql,代码行数:10,代码来源:plyql-executor.ts


示例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(';');
}
开发者ID:Ghostubborn,项目名称:pivot,代码行数:11,代码来源:executors.ts


示例11: fromJS

  static fromJS(parameters: SplitCombineJS): SplitCombine {
    var value: SplitCombineValue = {
      expression: Expression.fromJS(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);
  }
开发者ID:codeaudit,项目名称:pivot,代码行数:13,代码来源:split-combine.ts


示例12: getCountDistinctReferences

/**
 * Look for all instances of countDistinct($blah) and return the blahs
 * @param ex
 * @returns {string[]}
 */
function getCountDistinctReferences(ex: Expression): string[] {
  var references: string[] = [];
  ex.forEach((ex: Expression) => {
    if (ex instanceof ChainExpression) {
      var actions = ex.actions;
      for (var action of actions) {
        if (action.action === 'countDistinct') {
          var refExpression = action.expression;
          if (refExpression instanceof RefExpression) references.push(refExpression.name);
        }
      }
    }
  });
  return references;
}
开发者ID:coconutpalm,项目名称:pivot,代码行数:20,代码来源:executor.ts


示例13: return

 return (ex: Expression) => {
   return Qajax({
     method: "POST",
     url: url + '?by=' + getSplitsDescription(ex),
     data: {
       dataset: name,
       expression: ex.toJS()
     }
   })
     .then(Qajax.filterSuccess)
     .then(Qajax.toJSON)
     .then(
       (dataJS) => {
         return Dataset.fromJS(dataJS);
       },
       (xhr: XMLHttpRequest): Dataset => {
         throw new Error(JSON.parse(xhr.responseText).message);
       }
     );
 };
开发者ID:Ghostubborn,项目名称:pivot,代码行数:20,代码来源:executors.ts


示例14: return

 return (ex: Expression) => {
   return Qajax({
     method: "POST",
     url: url + '?by=' + getSplitsDescription(ex),
     data: {
       version: version,
       dataSource: name,
       expression: ex.toJS()
     }
   })
     .then(Qajax.filterSuccess)
     .then(Qajax.toJSON)
     .then(
       (dataJS) => {
         return Dataset.fromJS(dataJS);
       },
       (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);
       }
     );
 };
开发者ID:Rahul-Sindhu,项目名称:pivot,代码行数:24,代码来源:ajax.ts


示例15: executePlywood

export function executePlywood(expression: Expression, context: Datum, timezone: Timezone): Q.Promise<PlywoodValue> {
  return expression.compute(context, { timezone });
}
开发者ID:baeeq,项目名称:plyql,代码行数:3,代码来源:plyql-executor.ts


示例16: getVariablesFlatDataset

    Q.fcall(() => {
      var myContext = context;
      var match: string[];

      // Deal with "SELECT @@blah LIMIT 1" by de-sugaring
      if ((/SELECT\s+@@/i).test(sql)) {
        sql = sql.replace(/@@(?:global\.|session\.)?/g, '');
        myContext = {
          data: getVariablesFlatDataset()
        }
      }

      // Hack, treat USE `blah` as SET ... (ignores it)
      if (match = sql.match(/USE\s+`/i)) {
        sql = "SET NAMES 'utf8'";
      }

      // Handle connection id query
      if (match = sql.match(/SELECT\s+(CONNECTION_ID\(\s*\))/i)) {
        return {
          type: 'connectionId',
          name: match[1]
        }
      }

      try {
        var sqlParse = Expression.parseSQL(sql);
      } catch (e) {
        printError(sql, e);
        return {
          type: 'error',
          code: 1064, // You have an error in your SQL syntax
          message: e.message
        };
      }

      if (!sqlParse.verb) {
        return {
          type: 'error',
          code: 1064,
          message: `Must have a verb`
        };
      }

      switch (sqlParse.verb) {
        case 'SET':
          return {
            type: 'ok'
          };

        case 'SELECT':
          return executeSQLParse(sqlParse, myContext, timezone)
            .then((dataset: PlywoodValue): MySQLResult => {
              if (Dataset.isDataset(dataset)) {
                return {
                  type: 'dataset',
                  dataset,
                  table: sqlParse.table
                };
              } else {
                throw new Error('unexpected result from expression');
              }
            });

        default:
          return {
            type: 'error',
            code: 1337,
            message: `Permission to ${sqlParse.verb} denied`
          };
      }
    })
开发者ID:baeeq,项目名称:plyql,代码行数:72,代码来源:plyql-mysql-gateway.ts


示例17: run

export function run() {
  var parsed = parseArgs();

  if (parsed.argv.original.length === 0 || parsed['help']) {
    printUsage();
    return;
  }

  if (parsed['version']) {
    printVersion();
    return;
  }

  var verbose: boolean = parsed['verbose'];

  // Get allow
  var allows: string[] = parsed['allow'] || [];
  for (let allow of allows) {
    if (!(allow === 'eternity' || allow === 'select')) {
      console.log("Unexpected allow", allow);
      return;
    }
  }

  // Get forced attribute overrides
  var attributeOverrides: AttributeJSs = [];
  var forceUnique: string[] = parsed['force-unique'] || [];
  for (let attributeName of forceUnique) {
    attributeOverrides.push({ name: attributeName, special: 'unique' });
  }
  var forceHistogram: string[] = parsed['force-histogram'] || [];
  for (let attributeName of forceHistogram) {
    attributeOverrides.push({ name: attributeName, special: 'histogram' });
  }

  // Get output
  var output: string = (parsed['output'] || 'json').toLowerCase();
  if (output !== 'json' && output !== 'csv' && output !== 'tsv' && output !== 'flat') {
    console.log(`output must be one of json, csv, tsv, or flat (is ${output}})`);
    return;
  }

  // Get host
  var host: string = parsed['druid'] || parsed['host'];
  if (!host) {
    console.log("must have a host");
    return;
  }

  // Get SQL
  var query: string = parsed['query'];
  if (query) {
    try {
      var sqlParse = Expression.parseSQL(query);
    } catch (e) {
      console.log("Could not parse query as SQL:", e.message);
      return;
    }

    if (sqlParse.verb !== 'SELECT' && sqlParse.verb !== 'DESCRIBE') {
      console.log("SQL must be a SELECT or DESCRIBE query");
      return;
    }
  } else {
    console.log("no query found please use --query (-q) flag");
    return;
  }

  var expression = sqlParse.expression;

  if (verbose) {
    console.log('Parsed query as the following plywood expression (as JSON):');
    console.log(JSON.stringify(expression, null, 2));
    console.log('---------------------------');
  }

  var dataName = 'data';
  var dataSource: string;
  if (parsed['data-source']) {
    dataSource = parsed['data-source'];
  } else if (sqlParse.table) {
    dataName = sqlParse.table;
    dataSource = sqlParse.table;
  } else {
    console.log("must have data source");
    return;
  }

  var timeout: number = parsed.hasOwnProperty('timeout') ? parsed['timeout'] : 60000;

  var requester: Requester.PlywoodRequester<any>;
  requester = druidRequesterFactory({
    host: host,
    timeout
  });

  var retry: number = parsed.hasOwnProperty('retry') ? parsed['retry'] : 2;
  if (retry > 0) {
    requester = helper.retryRequesterFactory({
      requester: requester,
//.........这里部分代码省略.........
开发者ID:dkarpman,项目名称:plyql,代码行数:101,代码来源:cli.ts


示例18: equalsByExpression

 public equalsByExpression(other: SplitCombine): boolean {
   var { expression } = this;
   return SplitCombine.isSplitCombine(other) && expression.equals(other.expression);
 }
开发者ID:RaviNK,项目名称:pivot,代码行数:4,代码来源:split-combine.ts


示例19: toSplitExpression

 public toSplitExpression(): Expression {
   var { expression, bucketAction } = this;
   if (!bucketAction) return expression;
   return expression.performAction(bucketAction);
 }
开发者ID:RaviNK,项目名称:pivot,代码行数:5,代码来源:split-combine.ts


示例20: toSplitExpression

 public toSplitExpression(): Expression {
   var expression = this.expression;
   var bucketAction = this.bucketAction;
   if (!bucketAction) return expression;
   return expression.performAction(bucketAction);
 }
开发者ID:Ghostubborn,项目名称:pivot,代码行数:6,代码来源:split-combine.ts



注:本文中的plywood.Expression类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript plywood.LimitAction类代码示例发布时间:2022-05-25
下一篇:
TypeScript plywood.Dataset类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap