示例#1
0
bool CSVRowInputStream::read(MutableColumns & columns, RowReadExtension & ext)
{
    if (istr.eof())
        return false;

    updateDiagnosticInfo();

    String tmp;
    for (size_t input_position = 0; input_position < column_indexes_for_input_fields.size(); ++input_position)
    {
        const auto & column_index = column_indexes_for_input_fields[input_position];
        if (column_index)
        {
            skipWhitespacesAndTabs(istr);
            data_types[*column_index]->deserializeAsTextCSV(*columns[*column_index], istr, format_settings);
            skipWhitespacesAndTabs(istr);
        }
        else
        {
            readCSVString(tmp, istr, format_settings.csv);
        }

        skipDelimiter(istr, format_settings.csv.delimiter, input_position + 1 == column_indexes_for_input_fields.size());
    }

    fillUnreadColumnsWithDefaults(columns, ext);

    return true;
}
bool TabSeparatedRowInputStream::read(Block & block)
{
	updateDiagnosticInfo();

	size_t size = data_types.size();

	try
	{
		if (istr.eof())
			return false;

		for (size_t i = 0; i < size; ++i)
		{
			data_types[i].get()->deserializeTextEscaped(*block.unsafeGetByPosition(i).column.get(), istr);

			/// пропускаем разделители
			if (i + 1 == size)
			{
				if (!istr.eof())
				{
					if (unlikely(row_num == 1))
						checkForCarriageReturn(istr);

					assertChar('\n', istr);
				}
			}
			else
				assertChar('\t', istr);
		}
	}
	catch (Exception & e)
	{
		String verbose_diagnostic;
		{
			WriteBufferFromString diagnostic_out(verbose_diagnostic);
			printDiagnosticInfo(block, diagnostic_out);
		}

		e.addMessage("\n" + verbose_diagnostic);
		throw;
	}

	return true;
}