Exemplo n.º 1
0
def call_select(args):
    rows = select(
        args.QUERY,
        args.TESTSUITE)
    try:
        for row in rows:
            print(tsdb.join(row))
    except (BrokenPipeError):
        logger.info('broken pipe')
Exemplo n.º 2
0
def test_join():
    assert tsdb.join([None]) == ''
    assert tsdb.join(['one']) == 'one'
    assert tsdb.join([u'あ']) == u'あ'
    assert tsdb.join(['one', 'two']) == 'one@two'
    assert tsdb.join(['one', None, 'three']) == 'one@@three'
    assert tsdb.join(['one@', '\\two\nabc']) == 'one\\s@\\\\two\\nabc'
Exemplo n.º 3
0
    def process(self,
                cpu: interface.Processor,
                selector: Tuple[str, str] = None,
                source: tsdb.Database = None,
                fieldmapper: FieldMapper = None,
                gzip: bool = False,
                buffer_size: int = 1000) -> None:
        """
        Process each item in a [incr tsdb()] test suite.

        The output rows will be flushed to disk when the number of new
        rows in a table is *buffer_size*.

        Args:
            cpu (:class:`~delphin.interface.Processor`): processor
                interface (e.g., :class:`~delphin.ace.ACEParser`)
            selector: a pair of (table_name, column_name) that specify
                the table and column used for processor input (e.g.,
                `('item', 'i-input')`)
            source (:class:`TestSuite`, :class:`Table`): test suite or
                table from which inputs are taken; if `None`, use the
                current test suite
            fieldmapper (:class:`FieldMapper`): object for
                mapping response fields to [incr tsdb()] fields; if
                `None`, use a default mapper for the standard schema
            gzip: if `True`, compress non-empty tables with gzip
            buffer_size (int): number of output rows to hold in memory
                before flushing to disk; ignored if the test suite is all
                in-memory; if `None`, do not flush to disk
        Examples:
            >>> ts.process(ace_parser)
            >>> ts.process(ace_generator, 'result:mrs', source=ts2)
        """
        if selector is None:
            assert isinstance(cpu.task, str)
            input_table, input_column = _default_task_selectors[cpu.task]
        else:
            input_table, input_column = selector
        if (input_table not in self.schema
                or all(f.name != input_column
                       for f in self.schema[input_table])):
            raise ITSDBError('invalid table or column: {!s}, {!s}'.format(
                input_table, input_column))
        if source is None:
            source = self
        if fieldmapper is None:
            fieldmapper = FieldMapper()
        index = tsdb.make_field_index(source.schema[input_table])

        affected = set(fieldmapper.affected_tables).intersection(self.schema)
        for name in affected:
            self[name].clear()

        key_names = [f.name for f in source.schema[input_table] if f.is_key]

        for row in source[input_table]:
            datum = row[index[input_column]]
            keys = [row[index[name]] for name in key_names]
            keys_dict = dict(zip(key_names, keys))
            response = cpu.process_item(datum, keys=keys_dict)
            logger.info('Processed item {:>16}  {:>8} results'.format(
                tsdb.join(keys), len(response['results'])))
            for tablename, data in fieldmapper.map(response):
                _add_row(self, tablename, data, buffer_size)

        for tablename, data in fieldmapper.cleanup():
            _add_row(self, tablename, data, buffer_size)

        tsdb.write_database(self, self.path, gzip=gzip)
Exemplo n.º 4
0
 def __str__(self) -> str:
     return tsdb.join(self, self.fields)