From 52e3fe592f3631610b82502819ed91988af3936f Mon Sep 17 00:00:00 2001 From: shuwenwei <55970239+shuwenwei@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:00:52 +0800 Subject: [PATCH] rename table model fields (#114) --- client/tablet.go | 4 +-- .../table/table_session_pool_example.go | 6 ++-- example/table/table_session_example.go | 18 +++++------ test/e2e/e2e_table_test.go | 30 +++++++++---------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/client/tablet.go b/client/tablet.go index 7d8e253..6bbc779 100644 --- a/client/tablet.go +++ b/client/tablet.go @@ -36,8 +36,8 @@ type MeasurementSchema struct { type ColumnCategory int8 const ( - ID = iota - MEASUREMENT + TAG = iota + FIELD ATTRIBUTE ) diff --git a/example/session_pool/table/table_session_pool_example.go b/example/session_pool/table/table_session_pool_example.go index 950a11b..b9106c5 100644 --- a/example/session_pool/table/table_session_pool_example.go +++ b/example/session_pool/table/table_session_pool_example.go @@ -68,7 +68,7 @@ func putBackToSessionPoolExample() { }() checkError(session.ExecuteNonQueryStatement("create database " + dbName)) checkError(session.ExecuteNonQueryStatement("use " + dbName)) - checkError(session.ExecuteNonQueryStatement("create table table_of_" + dbName + " (id1 string id, id2 string id, s1 text measurement, s2 text measurement)")) + checkError(session.ExecuteNonQueryStatement("create table table_of_" + dbName + " (tag1 string tag, tag2 string tag, s1 text field, s2 text field)")) }() } wg.Wait() @@ -126,7 +126,7 @@ func sessionPoolWithSpecificDatabaseExample() { return } defer session.Close() - checkError(session.ExecuteNonQueryStatement("create table " + tableName + " (id1 string id, id2 string id, s1 text measurement, s2 text measurement)")) + checkError(session.ExecuteNonQueryStatement("create table " + tableName + " (tag1 string tag, tag2 string tag, s1 text field, s2 text field)")) }() } wg.Wait() @@ -156,7 +156,7 @@ func sessionPoolWithoutSpecificDatabaseExample() { defer session.Close() checkError(session.ExecuteNonQueryStatement("create database " + dbName)) checkError(session.ExecuteNonQueryStatement("use " + dbName)) - checkError(session.ExecuteNonQueryStatement("create table t1 (id1 string id, id2 string id, s1 text measurement, s2 text measurement)")) + checkError(session.ExecuteNonQueryStatement("create table t1 (tag1 string tag, tag2 string tag, s1 text field, s2 text field)")) }() } wg.Wait() diff --git a/example/table/table_session_example.go b/example/table/table_session_example.go index c2eb2f5..24eab7f 100644 --- a/example/table/table_session_example.go +++ b/example/table/table_session_example.go @@ -46,7 +46,7 @@ func main() { checkError(session.ExecuteNonQueryStatement("create database test_db")) checkError(session.ExecuteNonQueryStatement("use test_db")) - checkError(session.ExecuteNonQueryStatement("create table t1 (id1 string id, id2 string id, s1 text measurement, s2 text measurement)")) + checkError(session.ExecuteNonQueryStatement("create table t1 (tag1 string tag, tag2 string tag, s1 text field, s2 text field)")) insertRelationalTablet(session) showTables(session) query(session) @@ -63,11 +63,11 @@ func getTextValueFromDataSet(dataSet *client.SessionDataSet, columnName string) func insertRelationalTablet(session client.ITableSession) { tablet, err := client.NewRelationalTablet("t1", []*client.MeasurementSchema{ { - Measurement: "id1", + Measurement: "tag1", DataType: client.STRING, }, { - Measurement: "id2", + Measurement: "tag2", DataType: client.STRING, }, { @@ -78,7 +78,7 @@ func insertRelationalTablet(session client.ITableSession) { Measurement: "s2", DataType: client.TEXT, }, - }, []client.ColumnCategory{client.ID, client.ID, client.MEASUREMENT, client.MEASUREMENT}, 1024) + }, []client.ColumnCategory{client.TAG, client.TAG, client.FIELD, client.FIELD}, 1024) if err != nil { log.Fatal("Failed to create relational tablet {}", err) } @@ -86,8 +86,8 @@ func insertRelationalTablet(session client.ITableSession) { for row := 0; row < 16; row++ { ts++ tablet.SetTimestamp(ts, row) - tablet.SetValueAt("id1_field_"+strconv.Itoa(row), 0, row) - tablet.SetValueAt("id2_field_"+strconv.Itoa(row), 1, row) + tablet.SetValueAt("tag1_value_"+strconv.Itoa(row), 0, row) + tablet.SetValueAt("tag2_value_"+strconv.Itoa(row), 1, row) tablet.SetValueAt("s1_value_"+strconv.Itoa(row), 2, row) tablet.SetValueAt("s2_value_"+strconv.Itoa(row), 3, row) tablet.RowSize++ @@ -99,8 +99,8 @@ func insertRelationalTablet(session client.ITableSession) { for row := 0; row < 16; row++ { ts++ tablet.SetTimestamp(ts, row) - tablet.SetValueAt("id1_field_1", 0, row) - tablet.SetValueAt("id2_field_1", 1, row) + tablet.SetValueAt("tag1_value_1", 0, row) + tablet.SetValueAt("tag2_value_1", 1, row) tablet.SetValueAt("s1_value_"+strconv.Itoa(row), 2, row) tablet.SetValueAt("s2_value_"+strconv.Itoa(row), 3, row) @@ -143,7 +143,7 @@ func query(session client.ITableSession) { if !hasNext { break } - log.Printf("%v %v %v %v", getTextValueFromDataSet(dataSet, "id1"), getTextValueFromDataSet(dataSet, "id2"), getTextValueFromDataSet(dataSet, "s1"), getTextValueFromDataSet(dataSet, "s2")) + log.Printf("%v %v %v %v", getTextValueFromDataSet(dataSet, "tag1"), getTextValueFromDataSet(dataSet, "tag2"), getTextValueFromDataSet(dataSet, "s1"), getTextValueFromDataSet(dataSet, "s2")) } } diff --git a/test/e2e/e2e_table_test.go b/test/e2e/e2e_table_test.go index 3df5b6e..de930d3 100644 --- a/test/e2e/e2e_table_test.go +++ b/test/e2e/e2e_table_test.go @@ -183,7 +183,7 @@ func (s *e2eTableTestSuite) Test_GetSessionFromSessionPoolWithSpecificDatabase() session1, err := sessionPool.GetSession() assert.NoError(err) - s.checkError(session1.ExecuteNonQueryStatement("create table table_in_" + database + " (id1 string id, id2 string id, s1 text measurement, s2 text measurement)")) + s.checkError(session1.ExecuteNonQueryStatement("create table table_in_" + database + " (tag1 string tag, tag2 string tag, s1 text field, s2 text field)")) session1.Close() var wg sync.WaitGroup @@ -239,7 +239,7 @@ func (s *e2eTableTestSuite) Test_GetSessionFromSessionPoolWithSpecificDatabase() func (s *e2eTableTestSuite) Test_InsertTabletAndQuery() { assert := s.Require() - s.checkError(s.session.ExecuteNonQueryStatement("create table t1 (id1 string id, id2 string id, s1 text measurement, s2 text measurement)")) + s.checkError(s.session.ExecuteNonQueryStatement("create table t1 (tag1 string tag, tag2 string tag, s1 text field, s2 text field)")) timeoutInMs := int64(10000) @@ -255,11 +255,11 @@ func (s *e2eTableTestSuite) Test_InsertTabletAndQuery() { // insert relational tablet tablet, err := client.NewRelationalTablet("t1", []*client.MeasurementSchema{ { - Measurement: "id1", + Measurement: "tag1", DataType: client.STRING, }, { - Measurement: "id2", + Measurement: "tag2", DataType: client.STRING, }, { @@ -270,18 +270,18 @@ func (s *e2eTableTestSuite) Test_InsertTabletAndQuery() { Measurement: "s2", DataType: client.TEXT, }, - }, []client.ColumnCategory{client.ID, client.ID, client.MEASUREMENT, client.MEASUREMENT}, 1024) + }, []client.ColumnCategory{client.TAG, client.TAG, client.FIELD, client.FIELD}, 1024) assert.NoError(err) values := [][]interface{}{ - {"id1_field_1", "id2_field_1", "s1_value_1", "s2_value_1"}, - {"id1_field_1", "id2_field_1", "s1_value_2", "s2_value_2"}, - {"id1_field_1", "id2_field_1", nil, "s2_value_2"}, - {"id1_field_2", "id2_field_2", "s1_value_1", "s2_value_1"}, - {"id1_field_2", "id2_field_2", "s1_value_1", "s2_value_1"}, - {"id1_field_3", "id2_field_3", "s1_value_1", "s2_value_1"}, - {"id1_field_3", "id2_field_3", "s1_value_2", nil}, - {"id1_field_3", "id2_field_3", "s1_value_3", "s2_value_3"}, + {"tag1_value_1", "tag2_value_1", "s1_value_1", "s2_value_1"}, + {"tag1_value_1", "tag2_value_1", "s1_value_2", "s2_value_2"}, + {"tag1_value_1", "tag2_value_1", nil, "s2_value_2"}, + {"tag1_value_2", "tag2_value_2", "s1_value_1", "s2_value_1"}, + {"tag1_value_2", "tag2_value_2", "s1_value_1", "s2_value_1"}, + {"tag1_value_3", "tag2_value_3", "s1_value_1", "s2_value_1"}, + {"tag1_value_3", "tag2_value_3", "s1_value_2", nil}, + {"tag1_value_3", "tag2_value_3", "s1_value_3", "s2_value_3"}, } ts := int64(0) @@ -308,8 +308,8 @@ func (s *e2eTableTestSuite) Test_InsertTabletAndQuery() { break } assert.Equal(count, dataSet.GetInt64("time")) - assert.Equal(values[count][0], getValueFromDataSet(dataSet, "id1")) - assert.Equal(values[count][1], getValueFromDataSet(dataSet, "id2")) + assert.Equal(values[count][0], getValueFromDataSet(dataSet, "tag1")) + assert.Equal(values[count][1], getValueFromDataSet(dataSet, "tag2")) assert.Equal(values[count][2], getValueFromDataSet(dataSet, "s1")) assert.Equal(values[count][3], getValueFromDataSet(dataSet, "s2")) count++