• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang influxql.MustParseStatement函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/influxdb/influxdb/influxql.MustParseStatement函数的典型用法代码示例。如果您正苦于以下问题:Golang MustParseStatement函数的具体用法?Golang MustParseStatement怎么用?Golang MustParseStatement使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MustParseStatement函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestStatementExecutor_ExecuteStatement_DropServer

// Ensure a DROP SERVER statement can be executed.
func TestStatementExecutor_ExecuteStatement_DropServer(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.NodeFn = func(id uint64) (*meta.NodeInfo, error) {
		return &meta.NodeInfo{
			ID: 1, Host: "node1",
		}, nil
	}

	// Ensure Raft nodes cannot be dropped.
	e.Store.PeersFn = func() ([]string, error) {
		return []string{"node1"}, nil
	}
	if res := e.ExecuteStatement(influxql.MustParseStatement(`DROP SERVER 1`)); res.Err != meta.ErrNodeRaft {
		t.Fatalf("unexpected error: %s", res.Err)
	}

	// Ensure non-Raft nodes can be dropped.
	e.Store.PeersFn = func() ([]string, error) {
		return []string{"node2"}, nil
	}
	e.Store.DeleteNodeFn = func(id uint64, force bool) error {
		return nil
	}
	if res := e.ExecuteStatement(influxql.MustParseStatement(`DROP SERVER 1`)); res.Err != nil {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:kubernetes-up-and-running,项目名称:influxdb,代码行数:28,代码来源:statement_executor_test.go


示例2: TestStatementExecutor_ExecuteStatement_ShowServers

// Ensure a SHOW SERVERS statement can be executed.
func TestStatementExecutor_ExecuteStatement_ShowServers(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.NodesFn = func() ([]meta.NodeInfo, error) {
		return []meta.NodeInfo{
			{ID: 1, Host: "node0"},
			{ID: 2, Host: "node1"},
		}, nil
	}
	e.Store.PeersFn = func() ([]string, error) {
		return []string{"node0"}, nil
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`SHOW SERVERS`)); res.Err != nil {
		t.Fatal(res.Err)
	} else if !reflect.DeepEqual(res.Series, influxql.Rows{
		{
			Columns: []string{"id", "url", "raft"},
			Values: [][]interface{}{
				{uint64(1), "http://node0", true},
				{uint64(2), "http://node1", false},
			},
		},
	}) {
		t.Fatalf("unexpected rows: %s", spew.Sdump(res.Series))
	}
}
开发者ID:marcosnils,项目名称:influxdb,代码行数:27,代码来源:statement_executor_test.go


示例3: TestStatementExecutor_ExecuteStatement_CreateRetentionPolicy

// Ensure a CREATE RETENTION POLICY statement can be executed.
func TestStatementExecutor_ExecuteStatement_CreateRetentionPolicy(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.CreateRetentionPolicyFn = func(database string, rpi *meta.RetentionPolicyInfo) (*meta.RetentionPolicyInfo, error) {
		if database != "foo" {
			t.Fatalf("unexpected database: %s", database)
		} else if rpi.Name != "rp0" {
			t.Fatalf("unexpected name: %s", rpi.Name)
		} else if rpi.Duration != 2*time.Hour {
			t.Fatalf("unexpected duration: %v", rpi.Duration)
		} else if rpi.ReplicaN != 3 {
			t.Fatalf("unexpected replication factor: %v", rpi.ReplicaN)
		}
		return nil, nil
	}
	e.Store.SetDefaultRetentionPolicyFn = func(database, name string) error {
		if database != "foo" {
			t.Fatalf("unexpected database: %s", database)
		} else if name != "rp0" {
			t.Fatalf("unexpected name: %s", name)
		}
		return nil
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`CREATE RETENTION POLICY rp0 ON foo DURATION 2h REPLICATION 3 DEFAULT`)); res.Err != nil {
		t.Fatal(res.Err)
	} else if res.Series != nil {
		t.Fatalf("unexpected rows: %#v", res.Series)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:30,代码来源:statement_executor_test.go


示例4: TestStatementExecutor_ExecuteStatement_ShowSubscriptions

// Ensure a SHOW SUBSCRIPTIONS statement can be executed.
func TestStatementExecutor_ExecuteStatement_ShowSubscriptions(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.DatabasesFn = func() ([]meta.DatabaseInfo, error) {
		return []meta.DatabaseInfo{
			{
				Name: "db0",
				RetentionPolicies: []meta.RetentionPolicyInfo{
					{
						Name: "rp0",
						Subscriptions: []meta.SubscriptionInfo{
							{Name: "s0", Mode: "ALL", Destinations: []string{"udp://h0:1234", "udp://h1:1234"}},
							{Name: "s1", Mode: "ANY", Destinations: []string{"udp://h2:1234", "udp://h3:1234"}},
						},
					},
					{
						Name: "rp1",
						Subscriptions: []meta.SubscriptionInfo{
							{Name: "s2", Mode: "ALL", Destinations: []string{"udp://h4:1234", "udp://h5:1234"}},
						},
					},
				},
			},
			{
				Name: "db1",
				RetentionPolicies: []meta.RetentionPolicyInfo{
					{
						Name: "rp2",
						Subscriptions: []meta.SubscriptionInfo{
							{Name: "s3", Mode: "ANY", Destinations: []string{"udp://h6:1234", "udp://h7:1234"}},
						},
					},
				},
			},
		}, nil
	}

	stmt := influxql.MustParseStatement(`SHOW SUBSCRIPTIONS`)
	if res := e.ExecuteStatement(stmt); res.Err != nil {
		t.Fatal(res.Err)
	} else if !reflect.DeepEqual(res.Series, models.Rows{
		{
			Name:    "db0",
			Columns: []string{"retention_policy", "name", "mode", "destinations"},
			Values: [][]interface{}{
				{"rp0", "s0", "ALL", []string{"udp://h0:1234", "udp://h1:1234"}},
				{"rp0", "s1", "ANY", []string{"udp://h2:1234", "udp://h3:1234"}},
				{"rp1", "s2", "ALL", []string{"udp://h4:1234", "udp://h5:1234"}},
			},
		},
		{
			Name:    "db1",
			Columns: []string{"retention_policy", "name", "mode", "destinations"},
			Values: [][]interface{}{
				{"rp2", "s3", "ANY", []string{"udp://h6:1234", "udp://h7:1234"}},
			},
		},
	}) {
		t.Fatalf("unexpected rows: %s", spew.Sdump(res.Series))
	}
}
开发者ID:nickrobinson,项目名称:influxdb,代码行数:61,代码来源:statement_executor_test.go


示例5: TestStatementExecutor_ExecuteStatement_ShowGrantsFor

// Ensure a SHOW GRANTS FOR statement can be executed.
func TestStatementExecutor_ExecuteStatement_ShowGrantsFor(t *testing.T) {
	t.Skip("Intermittent test failure: issue 3028")
	e := NewStatementExecutor()
	e.Store.UserPrivilegesFn = func(username string) (map[string]influxql.Privilege, error) {
		if username != "dejan" {
			t.Fatalf("unexpected username: %s", username)
		}
		return map[string]influxql.Privilege{
			"dejan": influxql.ReadPrivilege,
			"golja": influxql.WritePrivilege,
		}, nil
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`SHOW GRANTS FOR dejan`)); res.Err != nil {
		t.Fatal(res.Err)
	} else if !reflect.DeepEqual(res.Series, influxql.Rows{
		{
			Columns: []string{"database", "privilege"},
			Values: [][]interface{}{
				{"dejan", "READ"},
				{"golja", "WRITE"},
			},
		},
	}) {
		t.Fatalf("unexpected rows: %s", spew.Sdump(res.Series))
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:28,代码来源:statement_executor_test.go


示例6: TestStatementExecutor_ExecuteStatement_CreateSubscription

// Ensure a CREATE SUBSCRIPTION statement can be executed.
func TestStatementExecutor_ExecuteStatement_CreateSubscription(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.CreateSubscriptionFn = func(database, rp, name, mode string, destinations []string) error {
		if database != "db0" {
			t.Fatalf("unexpected database: %s", database)
		} else if rp != "rp0" {
			t.Fatalf("unexpected rp: %s", rp)
		} else if name != "s0" {
			t.Fatalf("unexpected name: %s", name)
		} else if mode != "ANY" {
			t.Fatalf("unexpected mode: %s", mode)
		} else if len(destinations) != 2 {
			t.Fatalf("unexpected destinations: %s", destinations)
		} else if destinations[0] != "udp://h0:1234" {
			t.Fatalf("unexpected destinations[0]: %s", destinations[0])
		} else if destinations[1] != "udp://h1:1234" {
			t.Fatalf("unexpected destinations[1]: %s", destinations[1])
		}
		return nil
	}

	stmt := influxql.MustParseStatement(`CREATE SUBSCRIPTION s0 ON db0.rp0 DESTINATIONS ANY 'udp://h0:1234', 'udp://h1:1234'`)
	if res := e.ExecuteStatement(stmt); res.Err != nil {
		t.Fatal(res.Err)
	} else if res.Series != nil {
		t.Fatalf("unexpected rows: %#v", res.Series)
	}
}
开发者ID:nickrobinson,项目名称:influxdb,代码行数:29,代码来源:statement_executor_test.go


示例7: TestStatementExecutor_ExecuteStatement_RevokeAdmin_Err

// Ensure a REVOKE statement for admin privilege returns errors from the store.
func TestStatementExecutor_ExecuteStatement_RevokeAdmin_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.SetAdminPrivilegeFn = func(username string, admin bool) error {
		return errors.New("marker")
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`REVOKE ALL PRIVILEGES FROM susy`)); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:statement_executor_test.go


示例8: TestStatementExecutor_ExecuteStatement_ShowRetentionPolicies_Err

// Ensure a SHOW RETENTION POLICIES statement can return an error from the store.
func TestStatementExecutor_ExecuteStatement_ShowRetentionPolicies_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.DatabaseFn = func(name string) (*meta.DatabaseInfo, error) {
		return nil, errors.New("marker")
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`SHOW RETENTION POLICIES ON db0`)); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:statement_executor_test.go


示例9: TestStatementExecutor_ExecuteStatement_Grant_Err

// Ensure a GRANT statement returns errors from the store.
func TestStatementExecutor_ExecuteStatement_Grant_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.SetPrivilegeFn = func(username, database string, p influxql.Privilege) error {
		return errors.New("marker")
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`GRANT READ ON foo TO susy`)); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:statement_executor_test.go


示例10: TestStatementExecutor_ExecuteStatement_DropUser_Err

// Ensure a DROP USER statement returns errors from the store.
func TestStatementExecutor_ExecuteStatement_DropUser_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.DropUserFn = func(name string) error {
		return errors.New("marker")
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`DROP USER susy`)); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:statement_executor_test.go


示例11: TestStatementExecutor_ExecuteStatement_SetPassword_Err

// Ensure a SET PASSWORD statement returns errors from the store.
func TestStatementExecutor_ExecuteStatement_SetPassword_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.UpdateUserFn = func(name, password string) error {
		return errors.New("marker")
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`SET PASSWORD FOR susy = 'pass'`)); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:statement_executor_test.go


示例12: TestStatementExecutor_ExecuteStatement_CreateUser_Err

// Ensure a CREATE USER statement returns errors from the store.
func TestStatementExecutor_ExecuteStatement_CreateUser_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.CreateUserFn = func(name, password string, admin bool) (*meta.UserInfo, error) {
		return nil, errors.New("marker")
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`CREATE USER susy WITH PASSWORD 'pass'`)); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:statement_executor_test.go


示例13: TestStatementExecutor_ExecuteStatement_ShowRetentionPolicies_ErrDatabaseNotFound

// Ensure a SHOW RETENTION POLICIES statement can return an error if the database doesn't exist.
func TestStatementExecutor_ExecuteStatement_ShowRetentionPolicies_ErrDatabaseNotFound(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.DatabaseFn = func(name string) (*meta.DatabaseInfo, error) {
		return nil, nil
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`SHOW RETENTION POLICIES ON db0`)); res.Err != meta.ErrDatabaseNotFound {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:statement_executor_test.go


示例14: TestStatementExecutor_ExecuteStatement_CreateRetentionPolicy_Err

// Ensure a CREATE RETENTION POLICY statement returns errors from the store.
func TestStatementExecutor_ExecuteStatement_CreateRetentionPolicy_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.CreateRetentionPolicyFn = func(database string, rpi *meta.RetentionPolicyInfo) (*meta.RetentionPolicyInfo, error) {
		return nil, errors.New("marker")
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`CREATE RETENTION POLICY rp0 ON foo DURATION 2h REPLICATION 1`)); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:statement_executor_test.go


示例15: TestStatementExecutor_ExecuteStatement_ShowDatabases_Err

// Ensure a SHOW DATABASES statement returns errors from the store.
func TestStatementExecutor_ExecuteStatement_ShowDatabases_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.DatabasesFn = func() ([]meta.DatabaseInfo, error) {
		return nil, errors.New("marker")
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`SHOW DATABASES`)); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:statement_executor_test.go


示例16: TestStatementExecutor_ExecuteStatement_ShowSubscriptions_Err

// Ensure a SHOW SUBSCRIPTIONS statement can return an error from the store.
func TestStatementExecutor_ExecuteStatement_ShowSubscriptions_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.DatabasesFn = func() ([]meta.DatabaseInfo, error) {
		return nil, errors.New("marker")
	}

	stmt := influxql.MustParseStatement(`SHOW SUBSCRIPTIONS`)
	if res := e.ExecuteStatement(stmt); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatal(res.Err)
	}
}
开发者ID:nickrobinson,项目名称:influxdb,代码行数:12,代码来源:statement_executor_test.go


示例17: TestStatementExecutor_ExecuteStatement_DropSubscription_Err

// Ensure a DROP SUBSCRIPTION statement can return an error from the store.
func TestStatementExecutor_ExecuteStatement_DropSubscription_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.DropSubscriptionFn = func(database, rp, name string) error {
		return errors.New("marker")
	}

	stmt := influxql.MustParseStatement(`DROP SUBSCRIPTION s0 ON db0.rp0`)
	if res := e.ExecuteStatement(stmt); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:nickrobinson,项目名称:influxdb,代码行数:12,代码来源:statement_executor_test.go


示例18: TestStatementExecutor_ExecuteStatement_CreateSubscription_Err

// Ensure a CREATE SUBSCRIPTION statement can return an error from the store.
func TestStatementExecutor_ExecuteStatement_CreateSubscription_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.CreateSubscriptionFn = func(database, rp, name, mode string, destinations []string) error {
		return errors.New("marker")
	}

	stmt := influxql.MustParseStatement(`CREATE SUBSCRIPTION s0 ON db0.rp0 DESTINATIONS ANY 'udp://h0:1234', 'udp://h1:1234'`)
	if res := e.ExecuteStatement(stmt); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:nickrobinson,项目名称:influxdb,代码行数:12,代码来源:statement_executor_test.go


示例19: TestStatementExecutor_ExecuteStatement_ShowShardGroups

// Ensure a SHOW SHARD GROUPS statement can be executed.
func TestStatementExecutor_ExecuteStatement_ShowShardGroups(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.DatabasesFn = func() ([]meta.DatabaseInfo, error) {
		return []meta.DatabaseInfo{
			{
				Name: "foo",
				RetentionPolicies: []meta.RetentionPolicyInfo{
					{
						Name:     "rpi_foo",
						Duration: time.Second,
						ShardGroups: []meta.ShardGroupInfo{
							{
								ID:        66,
								StartTime: time.Unix(0, 0),
								EndTime:   time.Unix(1, 0),
							},
						},
					},
				},
			},
			{
				Name: "foo",
				RetentionPolicies: []meta.RetentionPolicyInfo{
					{
						Name:     "rpi_foo",
						Duration: time.Second,
						ShardGroups: []meta.ShardGroupInfo{
							{
								ID:        77,
								StartTime: time.Unix(2, 0),
								EndTime:   time.Unix(3, 0),
							},
						},
					},
				},
			},
		}, nil
	}

	if res := e.ExecuteStatement(influxql.MustParseStatement(`SHOW SHARD GROUPS`)); res.Err != nil {
		t.Fatal(res.Err)
	} else if !reflect.DeepEqual(res.Series, models.Rows{
		{
			Name:    "shard groups",
			Columns: []string{"id", "database", "retention_policy", "start_time", "end_time", "expiry_time"},
			Values: [][]interface{}{
				{uint64(66), "foo", "rpi_foo", "1970-01-01T00:00:00Z", "1970-01-01T00:00:01Z", "1970-01-01T00:00:02Z"},
				{uint64(77), "foo", "rpi_foo", "1970-01-01T00:00:02Z", "1970-01-01T00:00:03Z", "1970-01-01T00:00:04Z"},
			},
		},
	}) {
		t.Fatalf("unexpected rows: %s", spew.Sdump(res.Series))
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:55,代码来源:statement_executor_test.go


示例20: TestStatementExecutor_ExecuteStatement_DropContinuousQuery_Err

// Ensure a DROP CONTINUOUS QUERY statement can return an error from the store.
func TestStatementExecutor_ExecuteStatement_DropContinuousQuery_Err(t *testing.T) {
	e := NewStatementExecutor()
	e.Store.DropContinuousQueryFn = func(database, name string) error {
		return errors.New("marker")
	}

	stmt := influxql.MustParseStatement(`DROP CONTINUOUS QUERY cq0 ON db0`)
	if res := e.ExecuteStatement(stmt); res.Err == nil || res.Err.Error() != "marker" {
		t.Fatalf("unexpected error: %s", res.Err)
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:12,代码来源:statement_executor_test.go



注:本文中的github.com/influxdb/influxdb/influxql.MustParseStatement函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang influxql.NewParser函数代码示例发布时间:2022-05-23
下一篇:
Golang influxql.InspectDataType函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap