MCPcopy Create free account
hub / github.com/apecloud/myduckserver / buildCondenseDeltaSQL

Function buildCondenseDeltaSQL

delta/controller.go:654–697  ·  view source on GitHub ↗
(viewName string, appender *DeltaAppender)

Source from the content-addressed store, hash-verified

652}
653
654func buildCondenseDeltaSQL(viewName string, appender *DeltaAppender) string {
655 var (
656 augmentedSchema = appender.Schema()
657 pkList = getPrimaryKeyList(appender.BaseSchema())
658 builder strings.Builder
659 )
660 builder.Grow(512)
661 // Select the last complete row without aggregating into an unnamed struct.
662 // DuckDB 1.5 cannot extract fields from LAST(ROW(...)) reliably.
663 builder.WriteString("SELECT ")
664 for i, col := range augmentedSchema {
665 if i > 0 {
666 builder.WriteString(", ")
667 }
668 builder.WriteString(catalog.QuoteIdentifierANSI(col.Name))
669 if isTimestampType(col.Type) {
670 builder.WriteString("::TIMESTAMP")
671 }
672 builder.WriteString(" AS ")
673 builder.WriteString(catalog.QuoteIdentifierANSI(col.Name))
674 }
675 builder.WriteString(" FROM ")
676 builder.WriteString(viewName)
677 builder.WriteString(" QUALIFY ROW_NUMBER() OVER (PARTITION BY ")
678 builder.WriteString(pkList)
679 builder.WriteString(" ORDER BY txn_group, txn_seq, txn_stmt, action) = COUNT(*) OVER (PARTITION BY ")
680 builder.WriteString(pkList)
681 builder.WriteString(")")
682 return builder.String()
683}
684
685func isTimestampType(t sql.Type) bool {
686 if types.IsTimestampType(t) {
687 return true
688 }
689 if pgt, ok := t.(pgtypes.PostgresType); ok {
690 return pgt.PG.OID == pgtype.TimestampOID
691 }
692 return false
693}

Callers 2

handleZeroDeleteMethod · 0.85

Calls 7

QuoteIdentifierANSIFunction · 0.92
getPrimaryKeyListFunction · 0.85
isTimestampTypeFunction · 0.85
BaseSchemaMethod · 0.80
SchemaMethod · 0.45
GrowMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected