1// Copyright (c) 2014 Couchbase, Inc. 2// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 3// except in compliance with the License. You may obtain a copy of the License at 4// http://www.apache.org/licenses/LICENSE-2.0 5// Unless required by applicable law or agreed to in writing, software distributed under the 6// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 7// either express or implied. See the License for the specific language governing permissions 8// and limitations under the License. 9 10package algebra 11 12import ( 13 "encoding/json" 14 15 "github.com/couchbase/query/auth" 16 "github.com/couchbase/query/datastore" 17 "github.com/couchbase/query/errors" 18 "github.com/couchbase/query/expression" 19 "github.com/couchbase/query/value" 20) 21 22type BuildIndexes struct { 23 statementBase 24 25 keyspace *KeyspaceRef `json:"keyspace"` 26 using datastore.IndexType `json:"using"` 27 names []string `json:"names"` 28} 29 30func NewBuildIndexes(keyspace *KeyspaceRef, using datastore.IndexType, names ...string) *BuildIndexes { 31 rv := &BuildIndexes{ 32 keyspace: keyspace, 33 using: using, 34 names: names, 35 } 36 37 rv.stmt = rv 38 return rv 39} 40 41func (this *BuildIndexes) Accept(visitor Visitor) (interface{}, error) { 42 return visitor.VisitBuildIndexes(this) 43} 44 45func (this *BuildIndexes) Signature() value.Value { 46 return nil 47} 48 49func (this *BuildIndexes) Formalize() error { 50 return nil 51} 52 53func (this *BuildIndexes) MapExpressions(mapper expression.Mapper) error { 54 return nil 55} 56 57func (this *BuildIndexes) Expressions() expression.Expressions { 58 return nil 59} 60 61/* 62Returns all required privileges. 63*/ 64func (this *BuildIndexes) Privileges() (*auth.Privileges, errors.Error) { 65 privs := auth.NewPrivileges() 66 fullName := this.keyspace.FullName() 67 privs.Add(fullName, auth.PRIV_QUERY_BUILD_INDEX) 68 return privs, nil 69} 70 71func (this *BuildIndexes) Keyspace() *KeyspaceRef { 72 return this.keyspace 73} 74 75/* 76Returns the index type string for the using clause. 77*/ 78func (this *BuildIndexes) Using() datastore.IndexType { 79 return this.using 80} 81 82func (this *BuildIndexes) Names() []string { 83 return this.names 84} 85 86func (this *BuildIndexes) MarshalJSON() ([]byte, error) { 87 r := map[string]interface{}{"type": "BuildIndexes"} 88 r["keyspaceRef"] = this.keyspace 89 r["using"] = this.using 90 r["names"] = this.names 91 return json.Marshal(r) 92} 93 94func (this *BuildIndexes) Type() string { 95 return "BUILD_INDEX" 96} 97