Skip to content

Commit

Permalink
rename table model fields (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuwenwei authored Dec 27, 2024
1 parent 8ed5752 commit 52e3fe5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions client/tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type MeasurementSchema struct {
type ColumnCategory int8

const (
ID = iota
MEASUREMENT
TAG = iota
FIELD
ATTRIBUTE
)

Expand Down
6 changes: 3 additions & 3 deletions example/session_pool/table/table_session_pool_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions example/table/table_session_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
},
{
Expand All @@ -78,16 +78,16 @@ 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)
}
ts := time.Now().UTC().UnixNano() / 1000000
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++
Expand All @@ -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)

Expand Down Expand Up @@ -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"))
}
}

Expand Down
30 changes: 15 additions & 15 deletions test/e2e/e2e_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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,
},
{
Expand All @@ -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)
Expand All @@ -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++
Expand Down

0 comments on commit 52e3fe5

Please sign in to comment.