Returns a CQL query that can be used to recreate this aggregate. If `formatted` is set to :const:`True`, extra whitespace will be added to make the query more readable.
(self, formatted=False)
| 1021 | self.deterministic = deterministic |
| 1022 | |
| 1023 | def as_cql_query(self, formatted=False): |
| 1024 | """ |
| 1025 | Returns a CQL query that can be used to recreate this aggregate. |
| 1026 | If `formatted` is set to :const:`True`, extra whitespace will |
| 1027 | be added to make the query more readable. |
| 1028 | """ |
| 1029 | sep = '\n ' if formatted else ' ' |
| 1030 | keyspace = protect_name(self.keyspace) |
| 1031 | name = protect_name(self.name) |
| 1032 | type_list = ', '.join([types.strip_frozen(arg_type) for arg_type in self.argument_types]) |
| 1033 | state_func = protect_name(self.state_func) |
| 1034 | state_type = types.strip_frozen(self.state_type) |
| 1035 | |
| 1036 | ret = "CREATE AGGREGATE %(keyspace)s.%(name)s(%(type_list)s)%(sep)s" \ |
| 1037 | "SFUNC %(state_func)s%(sep)s" \ |
| 1038 | "STYPE %(state_type)s" % locals() |
| 1039 | |
| 1040 | ret += ''.join((sep, 'FINALFUNC ', protect_name(self.final_func))) if self.final_func else '' |
| 1041 | ret += ''.join((sep, 'INITCOND ', self.initial_condition)) if self.initial_condition is not None else '' |
| 1042 | ret += '{}DETERMINISTIC'.format(sep) if self.deterministic else '' |
| 1043 | |
| 1044 | return ret |
| 1045 | |
| 1046 | def export_as_string(self): |
| 1047 | return self.as_cql_query(formatted=True) + ';' |