Пример #1
0
func (rv *RangeVar) OpenRelation() (rel *access.Relation, err error) {
	/* TODO: Refactor this to RelnameGetOid() */
	class_rel, err := access.HeapOpen(access.ClassRelId)
	if err != nil {
		return nil, err
	}
	defer class_rel.Close()
	scankeys := []access.ScanKey{
		{access.Anum_class_relname, system.Datum(rv.RelationName)},
	}
	scan, err := class_rel.BeginScan(scankeys)
	if err != nil {
		return nil, err
	}
	defer scan.EndScan()
	tuple, err := scan.Next()
	if err != nil {
		return nil, errors.New("relation not found")
	}
	relid := tuple.Get(int32(1)).(system.Oid)

	return access.HeapOpen(relid)
}
Пример #2
0
func (scan *SeqScan) Init() {
	var err error
	scan.relation, err = access.HeapOpen(scan.RangeTable.RelId)
	if err != nil {
		/* TODO: do stuff */
	}
	emptykeys := []access.ScanKey{}
	scan.scan, err = scan.relation.BeginScan(emptykeys)
	if err != nil {
		/* TODO: do stuff */
	}

	/* Build the output tuple desc */
	attrs := make([]*access.Attribute, len(scan.SeqScan.TargetList))
	for i, tle := range scan.SeqScan.TargetList {
		attrs[i] = &access.Attribute{
			tle.ResName, tle.Expr.ResultType(),
		}
	}
}
Пример #3
0
func (parser *ParserImpl) transformExpr(node Node) (expr Expr, err error) {
	switch node.(type) {
	default:
		return nil, parseError("unknown node type")
	case *ColumnRef:
		colref := node.(*ColumnRef)
		/* TODO: use map instead of linear search? */
		found := false
		var variable Var
		for rteidx, rte := range parser.namespace {
			/* TODO: colref may have table name too */
			for attidx, attname := range rte.RefAlias.ColumnNames {
				if attname == colref.name {
					if found {
						return nil, parseError("ambiguous column reference")
					}
					found = true
					relation, err := access.HeapOpen(rte.RelId)
					if err != nil {
						return nil, err
					}
					tupdesc := relation.RelDesc

					variable.resultType = tupdesc.Attrs[attidx].AttType
					variable.VarNo = uint16(rteidx + 1)
					variable.VarAttNo = uint16(attidx + 1)
				}
			}

		}
		if !found {
			return nil, parseError("column reference not found")
		}

		return Expr(&variable), nil

	}

	panic("unreachable")
}