예제 #1
0
/*
Generate a Version 4 UUID as specified in RFC 4122, wrap it in a value
and return it. The UUID() function may return an error, if so return
a nil value UUID with the error.
*/
func (this *Uuid) Evaluate(item value.Value, context Context) (value.Value, error) {
	u, err := util.UUID()
	if err != nil {
		return nil, err
	}
	return value.NewValue(u), nil
}
예제 #2
0
func TestNewV4(t *testing.T) {
	u, err := util.UUID()
	if err != nil {
		t.Errorf("Unexpected error getting UUID: %s", err.Error())
	}
	if !parseUUIDRegex.MatchString(u) {
		t.Errorf("Expected string representation to be valid, given: %s", u)
	}
	fmt.Printf("\t UUID:  %s \n", u)
}
예제 #3
0
func (this *builder) VisitPrepare(stmt *algebra.Prepare) (interface{}, error) {
	pl, err := BuildPrepared(stmt.Statement(), this.datastore, this.systemstore, this.namespace, false)
	if err != nil {
		return nil, err
	}

	if stmt.Name() == "" {
		uuid, err := util.UUID()
		if err != nil {
			return nil, errors.NewPreparedNameError(err.Error())
		}
		pl.SetName(uuid)
	} else {
		pl.SetName(stmt.Name())
	}

	pl.SetText(stmt.Text())

	json_bytes, err := pl.MarshalJSON()
	if err != nil {
		return nil, err
	}

	var b bytes.Buffer
	w := gzip.NewWriter(&b)
	w.Write(json_bytes)
	w.Close()
	str := base64.StdEncoding.EncodeToString(b.Bytes())
	pl.SetEncodedPlan(str)
	val := value.NewValue(json_bytes)
	err = val.SetField("encoded_plan", value.NewValue(str))
	if err != nil {
		return nil, err
	}

	err = plan.AddPrepared(pl)
	if err != nil {
		return nil, err
	}

	return plan.NewPrepare(val), nil
}
예제 #4
0
파일: request.go 프로젝트: jmptrader/query
func NewBaseRequest(statement string, prepared *plan.Prepared, namedArgs map[string]value.Value, positionalArgs value.Values,
	namespace string, maxParallelism int, readonly, metrics, signature value.Tristate, consistency ScanConfiguration,
	client_id string, creds datastore.Credentials) *BaseRequest {
	rv := &BaseRequest{
		statement:      statement,
		prepared:       prepared,
		namedArgs:      namedArgs,
		positionalArgs: positionalArgs,
		namespace:      namespace,
		maxParallelism: maxParallelism,
		readonly:       readonly,
		signature:      signature,
		metrics:        metrics,
		consistency:    consistency,
		credentials:    creds,
		requestTime:    time.Now(),
		serviceTime:    time.Now(),
		state:          RUNNING,
		errors:         make(errors.ErrorChannel, _ERROR_CAP),
		warnings:       make(errors.ErrorChannel, _ERROR_CAP),
		closeNotify:    make(chan bool, 1),
		stopResult:     make(chan bool, 1),
		stopExecute:    make(chan bool, 1),
	}

	if maxParallelism <= 0 {
		maxParallelism = runtime.NumCPU()
	}

	rv.results = make(value.ValueChannel, maxParallelism)

	if logging.LogLevel() >= logging.TRACE {
		rv.phaseTimes = make(map[string]time.Duration, 8)
	}

	uuid, _ := util.UUID()
	rv.id = &requestIDImpl{id: uuid}
	rv.client_id = newClientContextIDImpl(client_id)
	return rv
}