(viewName string, appender *DeltaAppender)
| 652 | } |
| 653 | |
| 654 | func 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 | |
| 685 | func 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 | } |
no test coverage detected