1 import TableFunctionsFactory_util
as util
5 """Holds a `TYPE | ANNOTATIONS`-like structure.
20 return self.type.format_sizer()
31 return self.type.tostring()
34 return self.__class__(self.type.apply_column(), self.
annotations)
37 return self.__class__(self.type.apply_namespace(ns), self.
annotations)
40 return self.type.get_cpp_type()
43 real_arg_name = dict(self.
annotations).get(
'name',
None)
44 return self.type.format_cpp_type(idx,
45 use_generic_arg_name=use_generic_arg_name,
46 real_arg_name=real_arg_name,
50 if name.startswith(
'is_'):
51 return getattr(self.
type, name)
52 raise AttributeError(name)
56 """Holds a `NAME<ARGS>`-like structure.
60 assert isinstance(name, str)
61 assert isinstance(args, tuple)
or args
is None, args
66 return 'Bracket(%r, args=%r)' % (self.
name, self.
args)
71 return '%s<%s>' % (self.
name,
', '.
join(map(str, self.
args)))
76 return '%s<%s>' % (self.
name,
', '.
join(map(util.tostring, self.
args)))
79 """Normalize bracket for given kind
81 assert kind
in [
'input',
'output'], kind
85 if self.
name ==
'Cursor':
86 args = [(a
if a.is_column_any()
else Bracket(
'Column', args=(a,))).
normalize(kind=kind)
for a
in self.
args]
94 """Apply cursor to a non-cursor column argument type.
95 TODO: this method is currently unused but we should apply
96 cursor to all input column arguments in order to distingush
98 foo(Cursor(Column<int32>, Column<float>)) -> Column<int32>
99 foo(Cursor(Column<int32>), Cursor(Column<float>)) -> Column<int32>
100 that at the moment are treated as the same :(
103 return Bracket(
'Cursor', args=(self,))
112 if self.
name ==
'Cursor':
113 return Bracket(ns +
'::' + self.
name, args=tuple(a.apply_namespace(ns=ns)
for a
in self.
args))
114 if not self.name.startswith(ns +
'::'):
119 return self.name.rsplit(
"::", 1)[-1] ==
'Cursor'
122 return self.name.rsplit(
"::", 1)[-1].startswith(
'Array')
125 return self.name.rsplit(
"::", 1)[-1].startswith(
'Column')
128 return self.name.rsplit(
"::", 1)[-1].startswith(
'ColumnList')
131 return self.name.rsplit(
"::", 1)[-1].startswith(
'Column')
and not self.
is_column_list()
134 return self.name.rsplit(
"::", 1)[-1].endswith(
'TextEncodingDict')
137 return self.name.rsplit(
"::", 1)[-1] ==
'ArrayTextEncodingDict'
140 return self.name.rsplit(
"::", 1)[-1] ==
'ColumnTextEncodingDict'
143 return self.name.rsplit(
"::", 1)[-1] ==
'ColumnArrayTextEncodingDict'
146 return self.name.rsplit(
"::", 1)[-1] ==
'ColumnListTextEncodingDict'
149 return self.name.rsplit(
"::", 1)[-1]
in util.OutputBufferSizeTypes
152 return self.name.rsplit(
"::", 1)[-1] ==
'kUserSpecifiedRowMultiplier'
155 return self.name.rsplit(
"::", 1)[-1] ==
'kPreFlightParameter'
160 return self.name.rsplit(
"::", 1)[-1]
not in (
'kConstant',
'kTableFunctionSpecifiedParameter',
'kPreFlightParameter')
165 return 'TableFunctionOutputRowSizer{OutputBufferSizeType::%s, %s}' % (self.
name, val)
168 name = self.name.rsplit(
"::", 1)[-1]
171 if name.startswith(
'ColumnList'):
172 name = name.lstrip(
'ColumnList')
173 clsname =
'ColumnList'
174 elif name.startswith(
'Column'):
175 name = name.lstrip(
'Column')
177 if name.startswith(
'Array'):
178 name = name.lstrip(
'Array')
184 if name.startswith(
'Bool'):
186 elif name.startswith(
'Int'):
187 ctype = name.lower() +
'_t'
188 elif name
in [
'Double',
'Float']:
190 elif name ==
'TextEncodingDict':
192 elif name ==
'TextEncodingNone':
194 elif name ==
'Timestamp':
196 elif name ==
'DayTimeInterval':
198 elif name ==
'YearMonthTimeInterval':
200 elif name
in [
'GeoPoint',
'GeoLineString',
'GeoPolygon',
201 'GeoMultiPoint',
'GeoMultiLineString',
'GeoMultiPolygon']:
204 raise NotImplementedError(self)
207 if subclsname
is None:
208 return '%s<%s>' % (clsname, ctype)
209 return '%s<%s<%s>>' % (clsname, subclsname, ctype)
211 def format_cpp_type(self, idx, use_generic_arg_name=False, real_arg_name=None, is_input=True):
214 pass_by_value_typs =(
215 'bool',
'int8_t',
'int16_t',
'int32_t',
'int64_t',
'float',
216 'double',
'Timestamp',
'DayTimeInterval',
'YearMonthTimeInterval',
'TextEncodingDict')
219 pass_by_reference_typs =(
'Column',
'ColumnList',
'TextEncodingNone',
'Array')
221 if use_generic_arg_name:
222 arg_name =
'input' + str(idx)
if is_input
else 'output' + str(idx)
223 elif real_arg_name
is not None:
224 arg_name = real_arg_name
227 arg_name =
'input' + str(idx)
if is_input
else 'output' + str(idx)
228 const =
'const ' if is_input
else ''
230 if any(cpp_type.startswith(t)
for t
in pass_by_reference_typs):
231 return '%s%s& %s' % (const, cpp_type, arg_name), arg_name
232 elif any(cpp_type.startswith(t)
for t
in pass_by_value_typs):
233 return '%s %s' % (cpp_type, arg_name), arg_name
235 msg =(
'Argument passing policy for argument `%s` of C++ type `%s` is unspecified.'
236 ' Update pass_by_value_typs or pass_by_reference_typs in'
237 ' Declaration.format_cpp_type to indicate the desired argument'
238 ' passing policy.') %(arg_name, cpp_type)
239 raise NotImplementedError(msg)
243 """typ is a string in format NAME<ARGS> or NAME
244 Returns Bracket instance.
251 assert typ.endswith(
'>'), typ
252 name = typ[:i].
strip()
254 rest = typ[i + 1:-1].
strip()
256 i = util.find_comma(rest)
260 a, rest = rest[:i].rstrip(), rest[i + 1:].lstrip()
261 args.append(cls.parse(a))
264 name = util.translate_map.get(name, name)
265 return cls(name, args)
def is_array_text_encoding_dict
def is_column_list_text_encoding_dict
def is_column_array_text_encoding_dict
def is_any_text_encoding_dict
def is_column_text_encoding_dict
def is_output_buffer_sizer