objecttables

package module
v0.0.0-...-f7c0e24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

README

Mayfair object tables

This library gives 2D tables with as elements go struct types that are implement the FactI[K comparable] interface. The tables then can be combined in a RETE network to perform SQL like joins on the tables. The result table fullfills all the conditions (about one fact or binary conditions about two facts). These functions are used in the mayfair distributed database project.

Each fact that is stored in an element of a table is identified by its data sort name, e.g. "Person". In the fact itself the datasort is identified by its integer table index field Tix(). A one column object table stores instances of one data sort and corresponds somewhat with a SQL table in which each object's corresponds with a column in the SQL table.

the libraries can be tested by the command go test ./... the makefile is used to generate the stringer interface on the JoinType enum type.

The makefile has the following targets

  • make : generate the stringer files and build the code
  • make test : perform all tests

Documentation

Overview

Package objecttables

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

Package objecttables

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

Package objecttables

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

Index

Constants

View Source
const TIX = "Tixx"

Variables

This section is empty.

Functions

func CalcKeys

func CalcKeys[K comparable](u any) []K

func ClearTableIdx

func ClearTableIdx()

func GetClass

func GetClass(bs []byte) string

GetClass get the table name from a json byte string

func GetTableIdx

func GetTableIdx(table string) (int, bool)

func GetTableName

func GetTableName(idx int) (string, bool)

func MetaEqual

func MetaEqual[V comparable](t TableI[V], o TableI[V]) bool

MetaEqual check whether the meta datas of two columns are equal

func MkFactList

func MkFactList[T FactI[any]](items []T) []ut.Optional[FactI[any]]

MkFactList make a list of optional FactI[any] types of list that inherits FactI[any]

func PrintTableIndexes

func PrintTableIndexes() string

func ReadTable

func ReadTable(name string) ([][]string, error)

func StoreTableIdx

func StoreTableIdx(table string) int

Types

type AlphaNode

type AlphaNode[K comparable] struct {
	// contains filtered or unexported fields
}

func NewAlphaNode

func NewAlphaNode[K comparable](no int, tix int, preds []Pred[FactI[K]]) *AlphaNode[K]

func (*AlphaNode[K]) AddFacts

func (an *AlphaNode[K]) AddFacts(facts []ut.Optional[FactI[K]])

func (*AlphaNode[K]) AddMods

func (an *AlphaNode[K]) AddMods(mods []FactMod[K])

func (*AlphaNode[K]) Clear

func (an *AlphaNode[K]) Clear()

func (*AlphaNode[K]) GetTable

func (an *AlphaNode[K]) GetTable() TableI[FactI[K]]

func (*AlphaNode[K]) Propagate

func (an *AlphaNode[K]) Propagate()

func (*AlphaNode[K]) SetChild

func (an *AlphaNode[K]) SetChild(child NodeI[K])

func (*AlphaNode[K]) String

func (an *AlphaNode[K]) String() string

type BetaNode

type BetaNode[K comparable] struct {
	// contains filtered or unexported fields
}

func NewBetaNode

func NewBetaNode[K comparable](no int, joinType JoinType, left NodeI[K], right NodeI[K], preds []Bip[FactI[K]]) *BetaNode[K]

func (*BetaNode[K]) Clear

func (bn *BetaNode[K]) Clear()

func (*BetaNode[K]) GetTable

func (bn *BetaNode[K]) GetTable() TableI[FactI[K]]

func (*BetaNode[K]) Propagate

func (bn *BetaNode[K]) Propagate()

func (*BetaNode[K]) SetChild

func (bn *BetaNode[K]) SetChild(child NodeI[K])

func (*BetaNode[K]) String

func (bn *BetaNode[K]) String() string

type Bip

type Bip[V comparable] struct {
	No             int
	Test           func(ut.Optional[V], ut.Optional[V]) bool
	Table1, Table2 int
}

func NewBiPred

func NewBiPred[V comparable](no, t1, t2 int, test func(v1 ut.Optional[V], v2 ut.Optional[V]) bool) Bip[V]

func (*Bip[V]) GetTuple

func (b *Bip[V]) GetTuple() ut.Tuple[int]

type CombiningType

type CombiningType int
const (
	UNION CombiningType = iota
	UNION_ALL
	INTERSECT
	INTERSECT_ALL
	EXCEPT
	EXCEPT_ALL
	END_COMBINE
)

postgresql combining queries types

func CombTypeOf

func CombTypeOf(str string) CombiningType

func (CombiningType) String

func (i CombiningType) String() string

type Fact

type Fact[K comparable] struct {
	Tablex     string `json:"table-name"`
	Tixx       int    `json:"-"`
	CreateTime time.Time
	Cg         bool
}

func NewFact

func NewFact[K comparable](table string, tix int, cg bool) Fact[K]

func (*Fact[K]) CreationTime

func (f *Fact[K]) CreationTime() time.Time

func (*Fact[K]) Equals

func (f *Fact[K]) Equals(o FactI[K]) bool

func (*Fact[K]) FromBytes

func (f *Fact[K]) FromBytes(buf []byte) FactI[K]

func (*Fact[K]) Gc

func (f *Fact[K]) Gc() bool

func (*Fact[K]) Keys

func (f *Fact[K]) Keys() []K

func (*Fact[K]) SetTix

func (f *Fact[K]) SetTix(t int)

func (*Fact[K]) Table

func (f *Fact[K]) Table() string

func (*Fact[K]) Tix

func (f *Fact[K]) Tix() int

func (*Fact[K]) ToBytes

func (f *Fact[K]) ToBytes() []byte

type FactI

type FactI[K comparable] interface {
	Keys() []K
	Tix() int
	Table() string
	Equals(o FactI[K]) bool
	ToBytes() []byte
	FromBytes([]byte) FactI[K]
	CreationTime() time.Time
	Gc() bool
}

type FactMod

type FactMod[K comparable] struct {
	Trans TransactionType
	Table string
	Fact  FactI[K]
	Tix   int
}

func NewFactMod

func NewFactMod[K comparable](trans TransactionType, table string, fact FactI[K]) FactMod[K]

type Group

type Group[V comparable] struct {
	Group *ut.SimpleMultiKeyStore[any, V]
	Keys  []string
	Table int
}

Group grouping data output to the selection stage. The groups are stored in the Group field als the string of a list of keys

func NewGroup

func NewGroup[V comparable](gb []GroupBy, table int) *Group[V]

type GroupBy

type GroupBy struct {
	// contains filtered or unexported fields
}

func NewGroupBy

func NewGroupBy(table, col int, field string) GroupBy

type GroupSelect

type GroupSelect struct {
	// contains filtered or unexported fields
}

func NewGroupSelect

func NewGroupSelect(table int, field string, sel GroupSelection) GroupSelect

type GroupSelection

type GroupSelection int
const (
	COUNT GroupSelection = iota
	AVG
	MIN
	MAX
	SUM
	GRP_SELECT_NONE
)

func (GroupSelection) String

func (i GroupSelection) String() string

type JoinType

type JoinType int
const (
	INNERJOIN JoinType = iota
	CROSSJOIN
	JOIN
	NATURALJOIN
	LEFTJOIN
	RIGHTJOIN
	FULLJOIN
)

func JoinTypeOf

func JoinTypeOf(str string) JoinType

func (JoinType) String

func (i JoinType) String() string

type NodeI

type NodeI[K comparable] interface {
	// GetTable  the facts of an alpha node and the joined facts of a beta node are stored in a Table of objects */
	GetTable() TableI[FactI[K]]

	// SetChild   the nodes are part of a binary tree network, so each alpha and beta node has one child and
	SetChild(NodeI[K])

	// Propagate propagate the facts of the alpha nodes through the rete network */
	Propagate()
	// Clear  all data to make network ready for new calculations */
	Clear()
	String() string
	// contains filtered or unexported methods
}

type OrderBy

type OrderBy struct {
	// contains filtered or unexported fields
}

func NewOrderBy

func NewOrderBy(tix, col int, field string, dir SortDir) OrderBy

type Pred

type Pred[V comparable] struct {
	No    int
	Table int
	Test  func(f ut.Optional[V]) bool
}

func NewPred

func NewPred[V comparable](no, table int, test func(f ut.Optional[V]) bool) Pred[V]

type ReteNetwork

type ReteNetwork[K comparable] struct {
	Modified     bool
	NoIterations uint64
	// contains filtered or unexported fields
}

func NewReteNetwork

func NewReteNetwork[K comparable](as []*AlphaNode[K], bs []*BetaNode[K]) *ReteNetwork[K]

func (*ReteNetwork[K]) AddFacts

func (r *ReteNetwork[K]) AddFacts(facts []ut.Optional[FactI[K]])

func (*ReteNetwork[K]) AddMods

func (r *ReteNetwork[K]) AddMods(ms []FactMod[K])

func (*ReteNetwork[K]) Clear

func (r *ReteNetwork[K]) Clear()

func (*ReteNetwork[K]) GetTable

func (r *ReteNetwork[K]) GetTable() TableI[FactI[K]]

func (*ReteNetwork[K]) HasTable

func (r *ReteNetwork[K]) HasTable(tix int) bool

func (*ReteNetwork[K]) Propagate

func (r *ReteNetwork[K]) Propagate()

type Rowi

type Rowi[V comparable] interface {
	IsValue() bool
	Values() []ut.Optional[V]
	ValuesQ(int) []ut.Optional[V]
	Add(optional ut.Optional[V])
	HasTable(int) bool
	Tables() ([]int, bool)

	String() string
	Equals(rowi Rowi[V]) bool
	SetTables(tables []int)
	Update(i int, of ut.Optional[V])
	Delete(i int)
	// contains filtered or unexported methods
}

func NewNullRow

func NewNullRow[V comparable](n int) Rowi[V]

func NewRow

func NewRow[V comparable]() Rowi[V]

func NewRowF1

func NewRowF1[V comparable](v ut.Optional[V]) Rowi[V]

func NewRowFN

func NewRowFN[V comparable](vs []ut.Optional[V]) Rowi[V]

type SortDir

type SortDir int
const (
	ASC SortDir = iota
	DESC
	ORDER_NONE
)

type Table

type Table[V comparable] struct {
	// contains filtered or unexported fields
}

func MakeTable

func MakeTable(name string) (*Table[any], error)

func NewTable

func NewTable[V comparable]() *Table[V]

func NewTablePs

func NewTablePs[V comparable](ts []int, cs []string) *Table[V]

func SelectGroup

func SelectGroup[V comparable](res *Group[V], selections []GroupSelect) *Table[any]

func (*Table[V]) AddRow1

func (t *Table[V]) AddRow1(r Rowi[V])

func (*Table[V]) AddRowF1

func (t *Table[V]) AddRowF1(v ut.Optional[V])

func (*Table[V]) AddRowFN

func (t *Table[V]) AddRowFN(vs []ut.Optional[V])

func (*Table[V]) AddRowsFN

func (t *Table[V]) AddRowsFN(vs []ut.Optional[V])

func (*Table[V]) Clear

func (t *Table[V]) Clear()

func (*Table[any]) CmpCsv

func (t *Table[any]) CmpCsv(csvs [][]string) bool

func (*Table[V]) ColumnCount

func (t *Table[V]) ColumnCount() int

func (*Table[V]) Columns

func (t *Table[V]) Columns() []string

func (*Table[V]) CrossJoin

func (t *Table[V]) CrossJoin(o TableI[V]) TableI[V]

func (*Table[V]) DeleteF1

func (t *Table[V]) DeleteF1(of ut.Optional[V])

func (*Table[V]) Except

func (t *Table[V]) Except(o TableI[V]) TableI[V]

Except removes the rows of t which are in the table o

func (*Table[V]) ExceptAll

func (t *Table[V]) ExceptAll(o TableI[V]) TableI[V]

func (*Table[V]) FullJoin

func (t *Table[V]) FullJoin(o TableI[V], preds []Bip[V]) TableI[V]

FullJoin performs full outer join

func (*Table[V]) Get

func (t *Table[V]) Get(row, col int) ut.Optional[V]

func (*Table[V]) GetValues

func (t *Table[V]) GetValues() []ut.Optional[V]

func (*Table[V]) GroupBy

func (t *Table[V]) GroupBy(groups []GroupBy) *Group[V]

func (*Table[V]) InnerJoin

func (t *Table[V]) InnerJoin(o TableI[V], preds []Bip[V]) TableI[V]

func (*Table[V]) Intersect

func (t *Table[V]) Intersect(o TableI[V]) TableI[V]

Intersect adds common rows of two tables, eliminates the duplicate rows

func (*Table[V]) IntersectAll

func (t *Table[V]) IntersectAll(o TableI[V]) TableI[V]

Intersect adds common rows of two tables, eliminates the duplicate rows

func (*Table[V]) IsEmpty

func (t *Table[V]) IsEmpty() bool

func (*Table[V]) IsValue

func (t *Table[V]) IsValue() bool

func (*Table[V]) LeftJoin

func (t *Table[V]) LeftJoin(o TableI[V], preds []Bip[V]) TableI[V]

LeftJoin performs left outer join

func (*Table[V]) Limit

func (t *Table[V]) Limit(offset, limit int)

Limit takes a subset of the table rows starting at 'offset' index taking 'limit' rows of the table, below some SQL usages: SELECT * FROM Customers LIMIT 3; first 3 records SELECT * FROM Customers LIMIT 3 OFFSET 3; Returns rows 4, 5, and 6 SELECT * FROM Employees ORDER BY salary DESC LIMIT 5; Returns the five employees with the highest salaries. SELECT DISTINCT salary FROM Employees ORDER BY salary DESC LIMIT 1 OFFSET 1; Returns the second highest salary from the Employees table.

func (*Table[V]) NaturalJoin

func (t *Table[V]) NaturalJoin(o TableI[V]) TableI[V]

func (*Table[V]) OrderBy

func (t *Table[V]) OrderBy(obs []OrderBy)

func (*Table[V]) RemDuplicates

func (t *Table[V]) RemDuplicates() TableI[V]

func (*Table[V]) RightJoin

func (t *Table[V]) RightJoin(o TableI[V], preds []Bip[V]) TableI[V]

RightJoin performs right outer join

func (*Table[V]) RowCount

func (t *Table[V]) RowCount() int

func (*Table[V]) Rows

func (t *Table[V]) Rows() []Rowi[V]

func (*Table[V]) SameTables

func (t *Table[V]) SameTables(o TableI[V]) bool

func (*Table[V]) Selection

func (t *Table[V]) Selection(distinct bool, selections []TableSelect) TableI[any]

func (*Table[V]) String

func (t *Table[V]) String() string

func (*Table[V]) TableCount

func (t *Table[V]) TableCount() int

func (*Table[V]) Tables

func (t *Table[V]) Tables() []int

func (*Table[V]) Union

func (t *Table[V]) Union(o TableI[V]) TableI[V]

Union combines the rows of two tables, eliminates the duplicate rows

func (*Table[V]) UnionAll

func (t *Table[V]) UnionAll(o TableI[V]) TableI[V]

UnionAll combines the rows of two tables, does not eliminate the duplicate rows

func (*Table[V]) UpdateRowF1

func (t *Table[V]) UpdateRowF1(of ut.Optional[V])

type TableI

type TableI[V comparable] interface {
	IsValue() bool
	Rows() []Rowi[V]
	AddRow1(Rowi[V])
	AddRowF1(v ut.Optional[V])
	UpdateRowF1(of ut.Optional[V])
	DeleteF1(of ut.Optional[V])
	AddRowFN(v []ut.Optional[V])
	AddRowsFN(v []ut.Optional[V])

	RowCount() int
	TableCount() int
	ColumnCount() int
	Clear()
	Tables() []int
	Columns() []string
	SameTables(TableI[V]) bool
	InnerJoin(TableI[V], []Bip[V]) TableI[V]
	NaturalJoin(TableI[V]) TableI[V]
	CrossJoin(TableI[V]) TableI[V]
	LeftJoin(TableI[V], []Bip[V]) TableI[V]
	RightJoin(TableI[V], []Bip[V]) TableI[V]
	FullJoin(TableI[V], []Bip[V]) TableI[V]
	Union(TableI[V]) TableI[V]
	UnionAll(TableI[V]) TableI[V]
	Intersect(TableI[V]) TableI[V]
	IntersectAll(TableI[V]) TableI[V]
	Except(TableI[V]) TableI[V]
	ExceptAll(TableI[V]) TableI[V]
	IsEmpty() bool
	GetValues() []ut.Optional[V]
	Selection(bool, []TableSelect) TableI[any]
	OrderBy([]OrderBy)
	RemDuplicates() TableI[V]
	Limit(int, int)
	GroupBy([]GroupBy) *Group[V]
	Get(int, int) ut.Optional[V]
}

TableI for the natural join operation on two tables the value type V needs to be comparable

type TableSelect

type TableSelect struct {
	// contains filtered or unexported fields
}

func NewTableSelect

func NewTableSelect(table int, field, alias string, sel TableSelection) TableSelect

type TableSelection

type TableSelection int
const (
	ALL_TABLES TableSelection = iota
	SELECT_TABLES
	SELECT_VALUES
	TBL_SELECT_NONE
)

func (TableSelection) String

func (i TableSelection) String() string

type TransactionType

type TransactionType int
const (
	UPDATE TransactionType = iota
	INSERT
	DELETE
	ERROR
	NONE
)

func (TransactionType) String

func (i TransactionType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL