1
1
mirror of https://github.com/wader/fq.git synced 2024-12-26 23:15:04 +03:00

postgres: fix compilation, fix tests

This commit is contained in:
Pavel Safonov 2023-05-03 09:45:25 +03:00
parent bb2659d442
commit e5f15c5fed
26 changed files with 119 additions and 114 deletions

View File

@ -126,6 +126,9 @@ ogg_page OGG page
opus_packet Opus packet
pcap PCAP packet capture
pcapng PCAPNG packet capture
pg_btree PostgreSQL btree index file
pg_control PostgreSQL control file
pg_heap PostgreSQL heap file
png Portable Network Graphics file
prores_frame Apple ProRes frame
protobuf Protobuf

View File

@ -112,9 +112,9 @@ var (
Opus_Packet = &decode.Group{Name: "opus_packet"}
PCAP = &decode.Group{Name: "pcap"}
PCAPNG = &decode.Group{Name: "pcapng"}
PG_BTREE = "pg_btree"
PG_CONTROL = "pg_control"
PG_HEAP = "pg_heap"
PG_BTREE = &decode.Group{Name: "pg_btree"}
PG_CONTROL = &decode.Group{Name: "pg_control"}
PG_HEAP = &decode.Group{Name: "pg_heap"}
PNG = &decode.Group{Name: "png"}
Prores_Frame = &decode.Group{Name: "prores_frame"}
Protobuf = &decode.Group{Name: "protobuf"}

View File

@ -272,7 +272,7 @@ func decodeIndexTuples(btree *BTree, d *decode.D) {
d.FieldValueBool("has_nulls", hasNulls)
d.FieldValueBool("has_var_widths", hasVarWidths)
})
d.FieldValueU("size", size)
d.FieldValueUint("size", size)
if size < IndexTupleDataSize {
d.Fatalf("invalid size of tuple = %d\n", size)
}

View File

@ -8,8 +8,9 @@ import (
"time"
)
//typedef enum DBState
//{
// typedef enum DBState
//
// {
// DB_STARTUP = 0,
// DB_SHUTDOWNED,
// DB_SHUTDOWNED_IN_RECOVERY,
@ -17,8 +18,8 @@ import (
// DB_IN_CRASH_RECOVERY,
// DB_IN_ARCHIVE_RECOVERY,
// DB_IN_PRODUCTION
//} DBState;
var DBState = scalar.UToScalar{
// } DBState;
var DBState = scalar.UintMap{
0: {Sym: "DB_STARTUP"},
1: {Sym: "DB_SHUTDOWNED"},
2: {Sym: "DB_SHUTDOWNED_IN_RECOVERY"},
@ -28,13 +29,14 @@ var DBState = scalar.UToScalar{
6: {Sym: "DB_IN_PRODUCTION"},
}
//typedef enum WalLevel
//{
// typedef enum WalLevel
//
// {
// WAL_LEVEL_MINIMAL = 0,
// WAL_LEVEL_REPLICA,
// WAL_LEVEL_LOGICAL
//} WalLevel;
var WalLevel = scalar.SToScalar{
// } WalLevel;
var WalLevel = scalar.SintMap{
0: {Sym: "WAL_LEVEL_MINIMAL"},
1: {Sym: "WAL_LEVEL_REPLICA"},
2: {Sym: "WAL_LEVEL_LOGICAL"},
@ -42,8 +44,9 @@ var WalLevel = scalar.SToScalar{
type icuVersionMapper struct{}
func (m icuVersionMapper) MapScalar(s scalar.S) (scalar.S, error) {
a := s.ActualU()
func (m icuVersionMapper) MapUint(s scalar.Uint) (scalar.Uint, error) {
s.ScalarActual()
a := s.Actual
major := a & 0xff
minor := (a >> 8) & 0xff
v1 := (a >> 16) & 0xff
@ -56,8 +59,8 @@ var IcuVersionMapper = icuVersionMapper{}
type xLogRecPtrMapper struct{}
func (m xLogRecPtrMapper) MapScalar(s scalar.S) (scalar.S, error) {
v := s.ActualU()
func (m xLogRecPtrMapper) MapUint(s scalar.Uint) (scalar.Uint, error) {
v := s.Actual
s.Sym = fmt.Sprintf("%X/%X", v>>32, uint32(v))
return s, nil
}
@ -67,8 +70,8 @@ var LocPtrMapper = xLogRecPtrMapper{}
type nextFullXidMapper struct{}
func (m nextFullXidMapper) MapScalar(s scalar.S) (scalar.S, error) {
v := s.ActualU()
func (m nextFullXidMapper) MapUint(s scalar.Uint) (scalar.Uint, error) {
v := s.Actual
s.Sym = fmt.Sprintf("%d:%d", v>>32, uint32(v))
return s, nil
}
@ -77,8 +80,8 @@ var NextFullXidMapper = nextFullXidMapper{}
type timeMapper struct{}
func (m timeMapper) MapScalar(s scalar.S) (scalar.S, error) {
ut := s.ActualS()
func (m timeMapper) MapSint(s scalar.Sint) (scalar.Sint, error) {
ut := s.Actual
t := time.Unix(ut, 0)
s.Sym = t.UTC().Format(time.RFC1123)
return s, nil
@ -87,12 +90,14 @@ func (m timeMapper) MapScalar(s scalar.S) (scalar.S, error) {
var TimeMapper = timeMapper{}
// typedef enum
//{
//
// {
// PG_UNKNOWN = 0xFFFF,
// PG_ORIGINAL = 0,
// PGPRO_STANDARD = ('P'<<8|'P'),
// PGPRO_ENTERPRISE = ('P'<<8|'E'),
//} PgEdition;
// } PgEdition;
//
//nolint:revive
const (
PG_UNKNOWN = 0xFFFF
@ -108,8 +113,8 @@ const (
type versionMapper struct{}
func (m versionMapper) MapScalar(s scalar.S) (scalar.S, error) {
v := s.ActualU()
func (m versionMapper) MapUint(s scalar.Uint) (scalar.Uint, error) {
v := s.Actual
v1, v2 := ParsePgProVersion(uint32(v))
switch v1 {
case PG_UNKNOWN:
@ -134,8 +139,8 @@ func ParsePgProVersion(v uint32) (pgProVersion uint32, oriVer uint32) {
type hexMapper struct{}
func (m hexMapper) MapScalar(s scalar.S) (scalar.S, error) {
v := s.ActualU()
func (m hexMapper) MapUint(s scalar.Uint) (scalar.Uint, error) {
v := s.Actual
s.Sym = fmt.Sprintf("%X", v)
return s, nil
}

View File

@ -21,8 +21,8 @@ func TransactionIDIsNormal(xid uint64) bool {
type lpFlagsMapper struct{}
func (m lpFlagsMapper) MapScalar(s scalar.S) (scalar.S, error) {
switch s.ActualU() {
func (m lpFlagsMapper) MapUint(s scalar.Uint) (scalar.Uint, error) {
switch s.Actual {
case LP_UNUSED:
s.Sym = "LP_UNUSED"
case LP_NORMAL:
@ -41,8 +41,8 @@ type Mask struct {
Mask uint64
}
func (m Mask) MapScalar(s scalar.S) (scalar.S, error) {
m1 := s.ActualU()
func (m Mask) MapUint(s scalar.Uint) (scalar.Uint, error) {
m1 := s.Actual
v := IsMaskSet(m1, m.Mask)
s.Actual = v
return s, nil

View File

@ -92,9 +92,9 @@ func decodeItemIdsInternal(page *HeapPage, d *decode.D) {
itemID.Flags = uint32((itemIDData >> 15) & 0x3)
itemID.Len = uint32((itemIDData >> 17) & 0x7fff)
d.FieldValueU("lp_off", uint64(itemID.Off))
d.FieldValueU("lp_flags", uint64(itemID.Flags), common.LpFlagsMapper)
d.FieldValueU("lp_len", uint64(itemID.Len))
d.FieldValueUint("lp_off", uint64(itemID.Off))
d.FieldValueUint("lp_flags", uint64(itemID.Flags), common.LpFlagsMapper)
d.FieldValueUint("lp_len", uint64(itemID.Len))
page.ItemIds = append(page.ItemIds, itemID)
})

View File

@ -183,7 +183,7 @@ func decodeHeapPage(heap *Heap, d *decode.D, blockNumber uint32) {
d.FieldStruct("page_header", func(d *decode.D) {
heap.DecodePageHeaderData(page, d)
d.FieldValueU("pd_checksum_check", uint64(checkSum))
d.FieldValueUint("pd_checksum_check", uint64(checkSum))
sumEqual := page.PdChecksum == checkSum
d.FieldValueBool("pd_checksum_check_equal", sumEqual)
})
@ -398,8 +398,8 @@ type TransactionMapper struct {
Tuple *TupleD
}
func (m TransactionMapper) MapScalar(s scalar.S) (scalar.S, error) {
xid := s.ActualU()
func (m TransactionMapper) MapUint(s scalar.Uint) (scalar.Uint, error) {
xid := s.Actual
if m.Special.PdXidBase != 0 && m.Tuple.IsMulti && common.TransactionIDIsNormal(xid) {
xid64 := xid + m.Special.PdXidBase

View File

@ -6,7 +6,7 @@ import (
"github.com/wader/fq/pkg/scalar"
)
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
d.FieldU64("system_identifier")
d.FieldU32("pg_control_version", common.VersionMapper)
d.FieldU32("catalog_version_no")

View File

@ -76,7 +76,7 @@ import (
//
/* total size (bytes): 80 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -76,7 +76,7 @@ import (
//
/* total size (bytes): 88 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -74,7 +74,7 @@ import (
/* XXX 4-byte padding */
/* total size (bytes): 88 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -74,7 +74,7 @@ import (
/* XXX 4-byte padding */
//
/* total size (bytes): 88 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -80,7 +80,7 @@ import (
//
/* total size (bytes): 120 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -81,7 +81,7 @@ import (
//
/* total size (bytes): 120 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -81,7 +81,7 @@ import (
//
/* total size (bytes): 120 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -78,7 +78,7 @@ import (
//
/* total size (bytes): 120 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -78,7 +78,7 @@ import (
//
/* total size (bytes): 120 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -76,7 +76,7 @@ import (
//
/* total size (bytes): 120 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -78,7 +78,7 @@ import (
/* total size (bytes): 80 */
//
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -76,7 +76,7 @@ import (
//
/* total size (bytes): 80 */
//
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -75,7 +75,7 @@ import (
/* XXX 4-byte padding */
//
/* total size (bytes): 88 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -74,7 +74,7 @@ import (
/* XXX 4-byte padding */
//
/* total size (bytes): 88 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -74,7 +74,7 @@ import (
/* XXX 4-byte padding */
//
/* total size (bytes): 88 */
func DecodePgControl(d *decode.D, in any) any {
func DecodePgControl(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;

View File

@ -14,11 +14,10 @@ import (
var pgBTreeFS embed.FS
func init() {
interp.RegisterFormat(decode.Format{
Name: format.PG_BTREE,
interp.RegisterFormat(format.PG_BTREE, &decode.Format{
Description: "PostgreSQL btree index file",
DecodeFn: decodePgBTree,
DecodeInArg: format.PostgresBTreeIn{
DefaultInArg: format.PostgresBTreeIn{
Page: 0,
},
RootArray: true,
@ -27,10 +26,10 @@ func init() {
interp.RegisterFS(pgBTreeFS)
}
func decodePgBTree(d *decode.D, in any) any {
func decodePgBTree(d *decode.D) any {
d.Endian = decode.LittleEndian
pgIn, ok := in.(format.PostgresBTreeIn)
if !ok {
var pgIn format.PostgresBTreeIn
if !d.ArgAs(&pgIn) {
d.Fatalf("DecodeInArg must be PostgresBTreeIn!\n")
}
return postgres.DecodePgBTree(d, pgIn)

View File

@ -29,11 +29,10 @@ import (
var pgControlFS embed.FS
func init() {
interp.RegisterFormat(decode.Format{
Name: format.PG_CONTROL,
interp.RegisterFormat(format.PG_CONTROL, &decode.Format{
Description: "PostgreSQL control file",
DecodeFn: decodePgControl,
DecodeInArg: format.PostgresIn{
DefaultInArg: format.PostgresIn{
Flavour: "",
},
})
@ -72,55 +71,55 @@ const (
PG_FLAVOUR_PGPROEE15 = "pgproee15"
)
func decodePgControl(d *decode.D, in any) any {
func decodePgControl(d *decode.D) any {
d.Endian = decode.LittleEndian
pgIn, ok := in.(format.PostgresIn)
if !ok {
var pgIn format.PostgresIn
if !d.ArgAs(&pgIn) {
d.Fatalf("DecodeInArg must be PostgresIn!\n")
}
switch pgIn.Flavour {
case PG_FLAVOUR_POSTGRES10:
return postgres10.DecodePgControl(d, in)
return postgres10.DecodePgControl(d)
case PG_FLAVOUR_POSTGRES11:
return postgres11.DecodePgControl(d, in)
return postgres11.DecodePgControl(d)
case PG_FLAVOUR_POSTGRES12:
return postgres12.DecodePgControl(d, in)
return postgres12.DecodePgControl(d)
case PG_FLAVOUR_POSTGRES13:
return postgres13.DecodePgControl(d, in)
return postgres13.DecodePgControl(d)
case PG_FLAVOUR_POSTGRES14, PG_FLAVOUR_POSTGRES15, PG_FLAVOUR_PGPRO15:
return postgres14.DecodePgControl(d, in)
return postgres14.DecodePgControl(d)
case PG_FLAVOUR_PGPRO10:
return pgpro10.DecodePgControl(d, in)
return pgpro10.DecodePgControl(d)
case PG_FLAVOUR_PGPRO11:
return pgpro11.DecodePgControl(d, in)
return pgpro11.DecodePgControl(d)
case PG_FLAVOUR_PGPRO12:
return pgpro12.DecodePgControl(d, in)
return pgpro12.DecodePgControl(d)
case PG_FLAVOUR_PGPRO13:
return pgpro13.DecodePgControl(d, in)
return pgpro13.DecodePgControl(d)
case PG_FLAVOUR_PGPRO14:
return pgpro14.DecodePgControl(d, in)
return pgpro14.DecodePgControl(d)
case PG_FLAVOUR_PGPROEE10:
return pgproee10.DecodePgControl(d, in)
return pgproee10.DecodePgControl(d)
case PG_FLAVOUR_PGPROEE11:
return pgproee11.DecodePgControl(d, in)
return pgproee11.DecodePgControl(d)
case PG_FLAVOUR_PGPROEE12:
return pgproee12.DecodePgControl(d, in)
return pgproee12.DecodePgControl(d)
case PG_FLAVOUR_PGPROEE13:
return pgproee13.DecodePgControl(d, in)
return pgproee13.DecodePgControl(d)
case PG_FLAVOUR_PGPROEE14:
return pgproee14.DecodePgControl(d, in)
return pgproee14.DecodePgControl(d)
case PG_FLAVOUR_PGPROEE15:
return pgproee15.DecodePgControl(d, in)
return pgproee15.DecodePgControl(d)
default:
break
}
return probeForDecode(d, in)
return probeForDecode(d)
}
func probeForDecode(d *decode.D, in any) any {
func probeForDecode(d *decode.D) any {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
d.U64()
@ -132,39 +131,39 @@ func probeForDecode(d *decode.D, in any) any {
if pgProVersion == common.PG_ORIGINAL {
switch oriVersion {
case PG_CONTROL_VERSION_10:
return postgres10.DecodePgControl(d, in)
return postgres10.DecodePgControl(d)
case PG_CONTROL_VERSION_11:
return postgres11.DecodePgControl(d, in)
return postgres11.DecodePgControl(d)
case PG_CONTROL_VERSION_12:
return postgres12.DecodePgControl(d, in)
return postgres12.DecodePgControl(d)
case PG_CONTROL_VERSION_14:
return postgres14.DecodePgControl(d, in)
return postgres14.DecodePgControl(d)
}
}
if pgProVersion == common.PGPRO_STANDARD {
switch oriVersion {
case PG_CONTROL_VERSION_10:
return pgpro10.DecodePgControl(d, in)
return pgpro10.DecodePgControl(d)
case PG_CONTROL_VERSION_11:
return pgpro11.DecodePgControl(d, in)
return pgpro11.DecodePgControl(d)
case PG_CONTROL_VERSION_12:
return pgpro12.DecodePgControl(d, in)
return pgpro12.DecodePgControl(d)
case PG_CONTROL_VERSION_14:
return pgpro14.DecodePgControl(d, in)
return pgpro14.DecodePgControl(d)
}
}
if pgProVersion == common.PGPRO_ENTERPRISE {
switch oriVersion {
case PG_CONTROL_VERSION_10:
return pgproee10.DecodePgControl(d, in)
return pgproee10.DecodePgControl(d)
case PGPRO_CONTROL_VERSION_11:
return pgproee11.DecodePgControl(d, in)
return pgproee11.DecodePgControl(d)
case PG_CONTROL_VERSION_12:
return pgproee12.DecodePgControl(d, in)
return pgproee12.DecodePgControl(d)
case PG_CONTROL_VERSION_14:
return pgproee14.DecodePgControl(d, in)
return pgproee14.DecodePgControl(d)
}
}

View File

@ -18,11 +18,10 @@ import (
var pgHeapFS embed.FS
func init() {
interp.RegisterFormat(decode.Format{
Name: format.PG_HEAP,
interp.RegisterFormat(format.PG_HEAP, &decode.Format{
Description: "PostgreSQL heap file",
DecodeFn: decodePgheap,
DecodeInArg: format.PostgresHeapIn{
DefaultInArg: format.PostgresHeapIn{
Flavour: PG_FLAVOUR_POSTGRES14,
Page: 0,
Segment: 0,
@ -33,11 +32,11 @@ func init() {
interp.RegisterFS(pgHeapFS)
}
func decodePgheap(d *decode.D, in any) any {
func decodePgheap(d *decode.D) any {
d.Endian = decode.LittleEndian
pgIn, ok := in.(format.PostgresHeapIn)
if !ok {
var pgIn format.PostgresHeapIn
if !d.ArgAs(&pgIn) {
d.Fatalf("DecodeInArg must be PostgresIn!\n")
}