@@ -131,17 +131,15 @@ func (t *NormalizeQueryGenerator) BuildQuery(ctx context.Context) (string, error
131131 }
132132
133133 switch clickHouseType {
134- case "Time64(3)" , "Nullable(Time64(3))" :
135- // Time64 is a time-of-day type, parse from JSON string
136- // toTime64 converts string to Time64(3), returns NULL if string is NULL or invalid
134+ case "Time64(6)" , "Nullable(Time64(6))" :
137135 fmt .Fprintf (& projection ,
138- "toTime64(JSONExtractString(_peerdb_data, %s),3 ) AS %s," ,
136+ "toTime64(JSONExtractString(_peerdb_data, %s), 6 ) AS %s," ,
139137 peerdb_clickhouse .QuoteLiteral (colName ),
140138 peerdb_clickhouse .QuoteIdentifier (dstColName ),
141139 )
142140 if t .enablePrimaryUpdate {
143141 fmt .Fprintf (& projectionUpdate ,
144- "toTime64(JSONExtractString(_peerdb_match_data, %s),3 ) AS %s," ,
142+ "toTime64(JSONExtractString(_peerdb_match_data, %s), 6 ) AS %s," ,
145143 peerdb_clickhouse .QuoteLiteral (colName ),
146144 peerdb_clickhouse .QuoteIdentifier (dstColName ),
147145 )
@@ -160,34 +158,17 @@ func (t *NormalizeQueryGenerator) BuildQuery(ctx context.Context) (string, error
160158 )
161159 }
162160 case "DateTime64(6)" , "Nullable(DateTime64(6))" :
163- if colType == types .QValueKindTime || colType == types .QValueKindTimeTZ {
164- // parseDateTime64BestEffortOrNull for hh:mm:ss puts the year as current year
165- // (or previous year if result would be in future) so explicitly anchor to unix epoch
166- fmt .Fprintf (& projection ,
167- "parseDateTime64BestEffortOrNull('1970-01-01 ' || JSONExtractString(_peerdb_data, %s),6,'UTC') AS %s," ,
168- peerdb_clickhouse .QuoteLiteral (colName ),
169- peerdb_clickhouse .QuoteIdentifier (dstColName ),
170- )
171- if t .enablePrimaryUpdate {
172- fmt .Fprintf (& projectionUpdate ,
173- "parseDateTime64BestEffortOrNull('1970-01-01 ' || JSONExtractString(_peerdb_match_data, %s),6,'UTC') AS %s," ,
174- peerdb_clickhouse .QuoteLiteral (colName ),
175- peerdb_clickhouse .QuoteIdentifier (dstColName ),
176- )
177- }
178- } else {
179- fmt .Fprintf (& projection ,
180- "parseDateTime64BestEffortOrNull(JSONExtractString(_peerdb_data, %s),6,'UTC') AS %s," ,
161+ fmt .Fprintf (& projection ,
162+ "parseDateTime64BestEffortOrNull(JSONExtractString(_peerdb_data, %s),6,'UTC') AS %s," ,
163+ peerdb_clickhouse .QuoteLiteral (colName ),
164+ peerdb_clickhouse .QuoteIdentifier (dstColName ),
165+ )
166+ if t .enablePrimaryUpdate {
167+ fmt .Fprintf (& projectionUpdate ,
168+ "parseDateTime64BestEffortOrNull(JSONExtractString(_peerdb_match_data, %s),6,'UTC') AS %s," ,
181169 peerdb_clickhouse .QuoteLiteral (colName ),
182170 peerdb_clickhouse .QuoteIdentifier (dstColName ),
183171 )
184- if t .enablePrimaryUpdate {
185- fmt .Fprintf (& projectionUpdate ,
186- "parseDateTime64BestEffortOrNull(JSONExtractString(_peerdb_match_data, %s),6,'UTC') AS %s," ,
187- peerdb_clickhouse .QuoteLiteral (colName ),
188- peerdb_clickhouse .QuoteIdentifier (dstColName ),
189- )
190- }
191172 }
192173 case "Array(DateTime64(6))" , "Nullable(Array(DateTime64(6)))" :
193174 fmt .Fprintf (& projection ,
@@ -312,14 +293,17 @@ func (t *NormalizeQueryGenerator) BuildQuery(ctx context.Context) (string, error
312293 t .lastNormBatchID , t .endBatchID , peerdb_clickhouse .QuoteLiteral (t .TableName ))
313294 }
314295
315- chSettings := NewCHSettings (t .chVersion )
316- chSettings .Add (SettingThrowOnMaxPartitionsPerInsertBlock , "0" )
317- chSettings .Add (SettingTypeJsonSkipDuplicatedPaths , "1" )
296+ chSettings := peerdb_clickhouse . NewCHSettings (t .chVersion )
297+ chSettings .Add (peerdb_clickhouse . SettingThrowOnMaxPartitionsPerInsertBlock , "0" )
298+ chSettings .Add (peerdb_clickhouse . SettingTypeJsonSkipDuplicatedPaths , "1" )
318299 if t .cluster {
319- chSettings .Add (SettingParallelDistributedInsertSelect , "0" )
300+ chSettings .Add (peerdb_clickhouse . SettingParallelDistributedInsertSelect , "0" )
320301 }
321302 if t .version >= shared .InternalVersion_JsonEscapeDotsInKeys {
322- chSettings .Add (SettingJsonTypeEscapeDotsInKeys , "1" )
303+ chSettings .Add (peerdb_clickhouse .SettingJsonTypeEscapeDotsInKeys , "1" )
304+ }
305+ if t .version >= shared .InternalVersion_ClickHouseTime64 {
306+ chSettings .Add (peerdb_clickhouse .SettingEnableTimeTime64Type , "1" )
323307 }
324308
325309 insertIntoSelectQuery := fmt .Sprintf ("INSERT INTO %s %s %s%s" ,
0 commit comments