|
4 | 4 |
|
5 | 5 | #include <stdexcept> |
6 | 6 | #include <iostream> |
| 7 | +#include <cmath> |
7 | 8 |
|
8 | 9 | #if defined(_MSC_VER) |
9 | 10 | # pragma warning(disable : 4996) |
@@ -129,6 +130,36 @@ inline void DateExample(Client& client) { |
129 | 130 | client.Execute("DROP TABLE test.date"); |
130 | 131 | } |
131 | 132 |
|
| 133 | +inline void DateTime64Example(Client& client) { |
| 134 | + Block b; |
| 135 | + |
| 136 | + /// Create a table. |
| 137 | + client.Execute("CREATE TABLE IF NOT EXISTS test.date (d DateTime64(6)) ENGINE = Memory"); |
| 138 | + |
| 139 | + size_t precision = 6ul; |
| 140 | + auto d = std::make_shared<ColumnDateTime64>(precision); |
| 141 | + assert(d->GetPrecision() == precision); |
| 142 | + Int64 precision_multiplier = std::pow(10ull, precision); |
| 143 | + Int64 datetime = Int64(std::time(nullptr)) * precision_multiplier; |
| 144 | + |
| 145 | + d->Append(datetime); |
| 146 | + b.AppendColumn("d", d); |
| 147 | + client.Insert("test.date", b); |
| 148 | + |
| 149 | + client.Select("SELECT d FROM test.date", [precision_multiplier](const Block& block) |
| 150 | + { |
| 151 | + for (size_t c = 0; c < block.GetRowCount(); ++c) { |
| 152 | + auto col = block[0]->As<ColumnDateTime64>(); |
| 153 | + Int64 t = col->At(c) / precision_multiplier; |
| 154 | + std::cerr << std::asctime(std::localtime(&t)) << " " << std::endl; |
| 155 | + } |
| 156 | + } |
| 157 | + ); |
| 158 | + |
| 159 | + /// Delete table. |
| 160 | + client.Execute("DROP TABLE test.date"); |
| 161 | +} |
| 162 | + |
132 | 163 | inline void DecimalExample(Client& client) { |
133 | 164 | Block b; |
134 | 165 |
|
@@ -442,6 +473,7 @@ static void RunTests(Client& client) { |
442 | 473 | ArrayExample(client); |
443 | 474 | CancelableExample(client); |
444 | 475 | DateExample(client); |
| 476 | + DateTime64Example(client); |
445 | 477 | DecimalExample(client); |
446 | 478 | EnumExample(client); |
447 | 479 | ExecptionExample(client); |
|
0 commit comments