/*
   Code samples from:
   http://docs.basho.com/riak/kv/latest/developing/data-types/hyperloglogs/

   make sure these bucket-types are created:

   riak_admin bucket-type create hlls '{"props":{"datatype":"hll"}}'
*/
771672
func main() {
	//riak.EnableDebugLogging = true

	nodeOpts := &riak.NodeOptions{
		RemoteAddress:  "riak-test:10017",
		RequestTimeout: time.Second * 60,
	}

	var node *riak.Node
	var err error
	if node, err = riak.NewNode(nodeOpts); err != nil {
		fmt.Println(err.Error())
	}

	nodes := []*riak.Node{node}
	opts := &riak.ClusterOptions{
		Nodes: nodes,
	}

	cluster, err := riak.NewCluster(opts)
	if err != nil {
		fmt.Println(err.Error())
	}

	defer func() {
		if err = cluster.Stop(); err != nil {
			fmt.Println(err.Error())
		}
	}()

	if err = cluster.Start(); err != nil {
		fmt.Println(err.Error())
	}

	// ping
	ping := &riak.PingCommand{}
	if err = cluster.Execute(ping); err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("ping passed")
	}

	if err = assertHyperloglogStartsEmpty(cluster); err != nil {
		ErrExit(err)
	}

	if err = updateHyperloglog(cluster); err != nil {
		ErrExit(err)
	}

	if err = fetchHyperloglog(cluster); err != nil {
		ErrExit(err)
	}
}
383977
func (builder *UpdateMapCommandBuilder) WithBucketType(bucketType string) *UpdateMapCommandBuilder {
	builder.protobuf.Type = []byte(bucketType)
	return builder
}
63856
func (builder *SecondaryIndexQueryCommandBuilder) WithBucketType(bucketType string) *SecondaryIndexQueryCommandBuilder {
	builder.protobuf.Type = []byte(bucketType)
	return builder
}
616731
func Create(c *middleware.Context) {
	if c.Req.Method == "POST" {
		bucket, e := models.BucketCreate(c.Query("title"))
		if e != nil {
			fmt.Println(e)
			c.Error(500, e.Error())
			return
		}
		c.Redirect("/buckets/" + fmt.Sprint(bucket.Id))
		return
	}
	c.HTML(200, "buckets/create")
}
476591
def get_bucket_type_props(self, bucket_type):
        
        self._check_bucket_types(bucket_type)
        msg_code = riak.pb.messages.MSG_CODE_GET_BUCKET_TYPE_REQ
        codec = self._get_codec(msg_code)
        msg = codec.encode_get_bucket_type_props(bucket_type)
        resp_code, resp = self._request(msg, codec)
        return codec.decode_bucket_props(resp.props)
503106
func (builder *FetchBucketPropsCommandBuilder) WithBucketType(bucketType string) *FetchBucketPropsCommandBuilder {
	builder.protobuf.Type = []byte(bucketType)
	return builder
}
1099213
func (b *Bucket) Bucket(name []byte) *Bucket {
	if b.buckets != nil {
		if child := b.buckets[string(name)]; child != nil {
			return child
		}
	}

	// Move cursor to key.
	c := b.Cursor()
	k, v, flags := c.seek(name)

	// Return nil if the key doesn't exist or it is not a bucket.
	if !bytes.Equal(name, k) || (flags&bucketLeafFlag) == 0 {
		return nil
	}

	// Otherwise create a bucket and cache it.
	var child = b.openBucket(v)
	if b.buckets != nil {
		b.buckets[string(name)] = child
	}

	return child
}
1370635
function createReducer (source, options = {}) {
  if (isReducer(source)) {
    return source
  }

  source = normalizeInput(source)
  const reducerType = reducerTypes.find(r => r.isType(source))

  if (_.isUndefined(reducerType)) {
    const message = [
      'Invalid reducer type.',
      ' Could not find a matching reducer type while parsing the value:\n ',
      _.attempt(util.inspect, source),
      '\nTry using an Array, String, Object, or Function.\n',
      'More info: https://github.com/ViacomInc/data-point/tree/master/packages/data-point#reducers\n'
    ].join('')

    throw new Error(message)
  }

  // NOTE: recursive call
  const reducer = reducerType.create(createReducer, source)
  reducer[IS_REDUCER] = true
  if (_.has(options, 'default')) {
    reducer[DEFAULT_VALUE] = { value: options.default }
  }

  return Object.freeze(reducer)
}
1040515
func (builder *FetchMapCommandBuilder) WithBucketType(bucketType string) *FetchMapCommandBuilder {
	builder.protobuf.Type = []byte(bucketType)
	return builder
}
24511
func (builder *StoreBucketTypePropsCommandBuilder) WithBucketType(bucketType string) *StoreBucketTypePropsCommandBuilder {
	builder.protobuf.Type = []byte(bucketType)
	return builder
}
847011
func isHookType(hook *unstructured.Unstructured, hookType appv1.HookType) bool {
	annotations := hook.GetAnnotations()
	if annotations == nil {
		return false
	}
	resHookTypes := strings.Split(annotations[common.AnnotationKeyHook], ",")
	for _, ht := range resHookTypes {
		if string(hookType) == strings.TrimSpace(ht) {
			return true
		}
	}
	return false
}
506509
func generateListMultipartUploadsResponse(bucket string, multipartsInfo ListMultipartsInfo, encodingType string) ListMultipartUploadsResponse {
	listMultipartUploadsResponse := ListMultipartUploadsResponse{}
	listMultipartUploadsResponse.Bucket = bucket
	listMultipartUploadsResponse.Delimiter = s3EncodeName(multipartsInfo.Delimiter, encodingType)
	listMultipartUploadsResponse.IsTruncated = multipartsInfo.IsTruncated
	listMultipartUploadsResponse.EncodingType = encodingType
	listMultipartUploadsResponse.Prefix = s3EncodeName(multipartsInfo.Prefix, encodingType)
	listMultipartUploadsResponse.KeyMarker = s3EncodeName(multipartsInfo.KeyMarker, encodingType)
	listMultipartUploadsResponse.NextKeyMarker = s3EncodeName(multipartsInfo.NextKeyMarker, encodingType)
	listMultipartUploadsResponse.MaxUploads = multipartsInfo.MaxUploads
	listMultipartUploadsResponse.NextUploadIDMarker = multipartsInfo.NextUploadIDMarker
	listMultipartUploadsResponse.UploadIDMarker = multipartsInfo.UploadIDMarker
	listMultipartUploadsResponse.CommonPrefixes = make([]CommonPrefix, len(multipartsInfo.CommonPrefixes))
	for index, commonPrefix := range multipartsInfo.CommonPrefixes {
		listMultipartUploadsResponse.CommonPrefixes[index] = CommonPrefix{
			Prefix: s3EncodeName(commonPrefix, encodingType),
		}
	}
	listMultipartUploadsResponse.Uploads = make([]Upload, len(multipartsInfo.Uploads))
	for index, upload := range multipartsInfo.Uploads {
		newUpload := Upload{}
		newUpload.UploadID = upload.UploadID
		newUpload.Key = s3EncodeName(upload.Object, encodingType)
		newUpload.Initiated = upload.Initiated.UTC().Format(timeFormatAMZLong)
		listMultipartUploadsResponse.Uploads[index] = newUpload
	}
	return listMultipartUploadsResponse
}
502178
func (builder *UpdateGSetCommandBuilder) WithBucketType(bucketType string) *UpdateGSetCommandBuilder {
	builder.protobuf.Type = []byte(bucketType)
	return builder
}
910947
func NewJSONSchemaFromProps(t *Type, properties map[string]interface{}, typ, name string) JSONSchema {
	var required []string

	if isTypeArray(typ) {
		return newArraySchema(t, typ, name)
	}

	props := make(map[string]property, len(properties))
	for name := range properties {
		rp := t.GetProperty(name)
		if !isPropTypeSupported(rp) {
			continue
		}

		p := newProperty(rp)
		props[p.Name] = p
		if p.Required {
			required = append(required, p.Name)
		}
	}

	// we need it to be sorted for testing purpose
	sort.Strings(required)
	js := JSONSchema{
		Schema:     schemaVer,
		Name:       name,
		Type:       typ,
		T:          t,
		Properties: props,
		Required:   required,
	}
	if js.T == nil {
		js.T = &Type{
			Type:       typ,
			Properties: properties,
		}
	}
	return js
}
802642
func (apiDef *APIDefinition) createType(name string, tip interface{},
	inputProps map[interface{}]interface{}) bool {

	created := false
	// check that there is no type with this name
	if _, exist := apiDef.Types[name]; exist {
		return created
	}

	// convert the inputProps to properties
	props := make(map[string]interface{})

	for k, p := range inputProps {
		name, ok := k.(string)
		if !ok {
			panic(fmt.Errorf("property key:%v need to be a string", k))
		}
		props[name] = p
	}

	t := Type{
		Name:       name,
		Type:       tip,
		Properties: props,
	}
	apiDef.Types[name] = t
	created = true
	return created
}
350403
func (s *CreateBrokerRequest) SetHostInstanceType(v string) *CreateBrokerRequest {
	s.HostInstanceType = &v
	return s
}
458216
func (p *parser) prefixType(reg TypeRegistry, t *Type, prefix string) *Type {
	pre := TypeName(prefix)
	switch t.Variant {
	case TypeVariantAliasTypeDef:
		t.AliasTypeDef.Name = pre + t.AliasTypeDef.Name
		if !reg.IsBaseTypeName(t.AliasTypeDef.Type) {
			t.AliasTypeDef.Type = TypeRef(pre) + t.AliasTypeDef.Type
		}
	case TypeVariantStringTypeDef:
		t.StringTypeDef.Name = pre + t.StringTypeDef.Name
		if !reg.IsBaseTypeName(t.StringTypeDef.Type) {
			t.StringTypeDef.Type = TypeRef(pre) + t.StringTypeDef.Type
		}
	case TypeVariantNumberTypeDef:
		t.NumberTypeDef.Name = pre + t.NumberTypeDef.Name
		if !reg.IsBaseTypeName(t.NumberTypeDef.Type) {
			t.NumberTypeDef.Type = TypeRef(pre) + t.NumberTypeDef.Type
		}
	case TypeVariantArrayTypeDef:
		t.ArrayTypeDef.Name = pre + t.ArrayTypeDef.Name
		if !reg.IsBaseTypeName(t.ArrayTypeDef.Type) {
			t.ArrayTypeDef.Type = TypeRef(pre) + t.ArrayTypeDef.Type
		}
		if !reg.IsBaseTypeName(t.ArrayTypeDef.Items) {
			t.ArrayTypeDef.Items = TypeRef(pre) + t.ArrayTypeDef.Items
		}
	case TypeVariantMapTypeDef:
		t.MapTypeDef.Name = pre + t.MapTypeDef.Name
		if !reg.IsBaseTypeName(t.MapTypeDef.Type) {
			t.MapTypeDef.Type = TypeRef(pre) + t.MapTypeDef.Type
		}
		if t.MapTypeDef.Keys != "" && !reg.IsBaseTypeName(t.MapTypeDef.Keys) {
			t.MapTypeDef.Keys = TypeRef(pre) + t.MapTypeDef.Keys
		}
		if t.MapTypeDef.Items != "" && !reg.IsBaseTypeName(t.MapTypeDef.Items) {
			t.MapTypeDef.Items = TypeRef(pre) + t.MapTypeDef.Items
		}
	case TypeVariantStructTypeDef:
		t.StructTypeDef.Name = pre + t.StructTypeDef.Name
		if !reg.IsBaseTypeName(t.StructTypeDef.Type) {
			t.StructTypeDef.Type = TypeRef(pre) + t.StructTypeDef.Type
		}
		for _, f := range t.StructTypeDef.Fields {
			if !reg.IsBaseTypeName(f.Type) {
				f.Type = TypeRef(pre) + f.Type
			}
			if f.Keys != "" && !reg.IsBaseTypeName(f.Keys) {
				f.Keys = TypeRef(pre) + f.Keys
			}
			if f.Items != "" && !reg.IsBaseTypeName(f.Items) {
				f.Items = TypeRef(pre) + f.Items
			}
		}
	case TypeVariantBytesTypeDef:
		t.BytesTypeDef.Name = pre + t.BytesTypeDef.Name
		if !reg.IsBaseTypeName(t.BytesTypeDef.Type) {
			t.BytesTypeDef.Type = TypeRef(pre) + t.BytesTypeDef.Type
		}
	case TypeVariantEnumTypeDef:
		t.EnumTypeDef.Name = pre + t.EnumTypeDef.Name
		if !reg.IsBaseTypeName(t.EnumTypeDef.Type) {
			t.EnumTypeDef.Type = TypeRef(pre) + t.EnumTypeDef.Type
		}
	case TypeVariantUnionTypeDef:
		t.UnionTypeDef.Name = pre + t.UnionTypeDef.Name
		if !reg.IsBaseTypeName(t.UnionTypeDef.Type) {
			t.UnionTypeDef.Type = TypeRef(pre) + t.UnionTypeDef.Type
		}
		for i := 0; i < len(t.UnionTypeDef.Variants); i++ {
			if !reg.IsBaseTypeName(t.UnionTypeDef.Variants[i]) {
				t.UnionTypeDef.Variants[i] = TypeRef(pre) + t.UnionTypeDef.Variants[i]
			}
		}
	case TypeVariantBaseType:
		return nil
	}
	return t
}