MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / generate

Method generate

src/Processors/Sources/SQLiteSource.cpp:58–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58Chunk SQLiteSource::generate()
59{
60 LOG_TEST(getLogger("SQLiteSource"), "Generate a chunk");
61
62 if (!compiled_statement)
63 return {};
64
65 MutableColumns columns = description.sample_block.cloneEmptyColumns();
66 size_t num_rows = 0;
67
68 while (true)
69 {
70 int status = sqlite3_step(compiled_statement.get());
71
72 if (status == SQLITE_INTERRUPT)
73 {
74 compiled_statement.reset();
75 break;
76 }
77
78 if (status == SQLITE_BUSY)
79 {
80 continue;
81 }
82 if (status == SQLITE_DONE)
83 {
84 compiled_statement.reset();
85 break;
86 }
87 if (status != SQLITE_ROW)
88 {
89 throw Exception(
90 ErrorCodes::SQLITE_ENGINE_ERROR,
91 "Expected SQLITE_ROW status, but got status {}. Error: {}, Message: {}",
92 status,
93 sqlite3_errstr(status),
94 sqlite3_errmsg(sqlite_db.get()));
95 }
96
97 int column_count = sqlite3_column_count(compiled_statement.get());
98
99 for (int column_index = 0; column_index < column_count; ++column_index)
100 {
101 if (sqlite3_column_type(compiled_statement.get(), column_index) == SQLITE_NULL)
102 {
103 columns[column_index]->insertDefault();
104 continue;
105 }
106
107 auto & [type, is_nullable] = description.types[column_index];
108 const auto & sample = description.sample_block.getByPosition(column_index);
109 if (is_nullable)
110 {
111 ColumnNullable & column_nullable = assert_cast<ColumnNullable &>(*columns[column_index]);
112 const auto & data_type = assert_cast<const DataTypeNullable &>(*sample.type);
113 insertValue(column_nullable.getNestedColumn(), type, column_index, *data_type.getNestedType());
114 column_nullable.getNullMapData().emplace_back(false);
115 }

Callers

nothing calls this directly

Calls 10

getNestedTypeMethod · 0.80
insertValueFunction · 0.70
getLoggerFunction · 0.50
ExceptionClass · 0.50
ChunkClass · 0.50
cloneEmptyColumnsMethod · 0.45
getMethod · 0.45
resetMethod · 0.45
insertDefaultMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected