Beispiel #1
0
  def parse(cls, _dict):
    op = _dict.pop('op')
    assert op in Aggregator.Op.values()

    _dict['arguments'] = map(Value.parse, _dict.get('arguments', []))

    if op in (Aggregator.Op.MIN, Aggregator.Op.MAX,
              Aggregator.Op.AVG, Aggregator.Op.SUM):
      assert len(_dict['arguments']) == 1
    if op == Aggregator.Op.COUNT:
      assert len(_dict['arguments']) in (0, 1)

    return getattr(sys.modules[__name__], Enum.titlecase(op))(**_dict)
Beispiel #2
0
  def parse(cls, _dict):
    op = _dict.pop('op')
    assert op in Aggregator.Op.values()

    _dict['arguments'] = map(Value.parse, _dict.get('arguments', []))

    if op in (Aggregator.Op.MIN, Aggregator.Op.MAX,
              Aggregator.Op.AVG, Aggregator.Op.SUM):
      assert len(_dict['arguments']) == 1
    if op == Aggregator.Op.COUNT:
      assert len(_dict['arguments']) in (0, 1)

    return getattr(sys.modules[__name__], Enum.titlecase(op))(**_dict)
Beispiel #3
0
 def parse(cls, _dict):
   _dict['arguments'] = map(Value.parse, _dict['arguments'])
   name = _dict.pop('name')
   assert name in Function.Name.values()
   return getattr(sys.modules[__name__], Enum.titlecase(name))(**_dict)
Beispiel #4
0
  DAY = 'day'
  MONTH = 'month'
  YEAR = 'year'


class DatePartUnit(_DateUnit):
  WEEK_DAY = 'week_day'


class DateTruncUnit(_DateUnit):
  WEEK = 'week'


# Create classes for all Function.Name types.
for typ in Function.Name.values():
  class_name = Enum.titlecase(typ)
  attrs = {'name': typ}
  if class_name == 'DateTrunc':
    attrs['Unit'] = DateTruncUnit
  elif class_name == 'DatePart':
    attrs['Unit'] = DatePartUnit
  typ = type(class_name, (Function, ), attrs)
  setattr(sys.modules[__name__], class_name, typ)


class Property(Value):
  def __init__(self, name, default=None, **kwargs):
    self.type = Value.Type.PROPERTY
    self.name = name
    self.default = default
    super(Property, self).__init__(**kwargs)
Beispiel #5
0
    op = _dict.pop('op')
    assert op in Aggregator.Op.values()

    _dict['arguments'] = map(Value.parse, _dict.get('arguments', []))

    if op in (Aggregator.Op.MIN, Aggregator.Op.MAX,
              Aggregator.Op.AVG, Aggregator.Op.SUM):
      assert len(_dict['arguments']) == 1
    if op == Aggregator.Op.COUNT:
      assert len(_dict['arguments']) in (0, 1)

    return getattr(sys.modules[__name__], Enum.titlecase(op))(**_dict)

# Create classes for all Aggregator.Op types.
for op in Aggregator.Op.values():
  class_name = Enum.titlecase(op)
  typ = type(class_name, (Aggregator, ), {'op': op})
  setattr(sys.modules[__name__], class_name, typ)


class GroupBy(Node):
  def __init__(self, values):
    if not isinstance(values, list):
      values = [values]
    self.values = values

  def to_dict(self):
    return map(lambda v: v.to_dict(), self.values)

  @classmethod
  def parse(cls, _list):
Beispiel #6
0
    op = _dict.pop('op')
    assert op in Aggregator.Op.values()

    _dict['arguments'] = map(Value.parse, _dict.get('arguments', []))

    if op in (Aggregator.Op.MIN, Aggregator.Op.MAX,
              Aggregator.Op.AVG, Aggregator.Op.SUM):
      assert len(_dict['arguments']) == 1
    if op == Aggregator.Op.COUNT:
      assert len(_dict['arguments']) in (0, 1)

    return getattr(sys.modules[__name__], Enum.titlecase(op))(**_dict)

# Create classes for all Aggregator.Op types.
for op in Aggregator.Op.values():
  class_name = Enum.titlecase(op)
  typ = type(class_name, (Aggregator, ), {'op': op})
  setattr(sys.modules[__name__], class_name, typ)


class GroupBy(Node):
  def __init__(self, values):
    if not isinstance(values, list):
      values = [values]
    self.values = values

  def to_dict(self):
    return map(lambda v: v.to_dict(), self.values)

  @classmethod
  def parse(cls, _list):