Example #1
0
// expandTableGlob expands wildcards from the end of `expr` and
// returns the list of matching tables.
// `expr` is possibly modified to be qualified with the database it refers to.
// `expr` is assumed to be of one of several forms:
// 		database.table
// 		table
// 		*
func (p *planner) expandTableGlob(expr *parser.QualifiedName) (
	parser.QualifiedNames, *roachpb.Error) {
	if len(expr.Indirect) == 0 {
		return parser.QualifiedNames{expr}, nil
	}

	if err := expr.QualifyWithDatabase(p.session.Database); err != nil {
		return nil, roachpb.NewError(err)
	}
	// We must have a single indirect: either .table or .*
	if len(expr.Indirect) != 1 {
		return nil, roachpb.NewErrorf("invalid table glob: %s", expr)
	}

	switch expr.Indirect[0].(type) {
	case parser.NameIndirection:
		return parser.QualifiedNames{expr}, nil
	case parser.StarIndirection:
		dbDesc, pErr := p.getDatabaseDesc(string(expr.Base))
		if pErr != nil {
			return nil, pErr
		}
		tableNames, pErr := p.getTableNames(dbDesc)
		if pErr != nil {
			return nil, pErr
		}
		return tableNames, nil
	default:
		return nil, roachpb.NewErrorf("invalid table glob: %s", expr)
	}
}