Repository: oom-ai/oomstore
Pull request #904 (2022-01-05 10:15:05)

refactor: remove entity length


Patch:
diff --git a/README.md b/README.md
index 311a328c..a5909324 100644
--- a/README.md
+++ b/README.md
@@ -80,7 +80,6 @@ metadata-store: *pg
 ```yaml
 kind: Entity
 name: user
-length: 8
 description: 'user ID'
 groups:
 - name: account
diff --git a/internal/database/dbutil/schema.go b/internal/database/dbutil/schema.go
index 82ffe28d..b23ae56c 100644
--- a/internal/database/dbutil/schema.go
+++ b/internal/database/dbutil/schema.go
@@ -80,10 +80,10 @@ func parseColumns(entity *types.Entity, isCDC bool, features types.FeatureList,
 	{
 		c := Column{Name: entity.Name, ValueType: types.String}
 		switch backend {
-		case types.BackendCassandra, types.BackendSQLite:
+		case types.BackendCassandra, types.BackendSQLite, types.BackendPostgres, types.BackendRedshift, types.BackendSnowflake:
 			c.DbType = "TEXT"
-		case types.BackendPostgres, types.BackendRedshift, types.BackendSnowflake, types.BackendMySQL:
-			c.DbType = fmt.Sprintf(`VARCHAR(%d)`, entity.Length)
+		case types.BackendMySQL:
+			c.DbType = "VARCHAR(255)"
 		case types.BackendBigQuery:
 			c.DbType = "STRING"
 		default:
diff --git a/internal/database/metadata/mysql/entity.go b/internal/database/metadata/mysql/entity.go
index eb3066ca..80db89fe 100644
--- a/internal/database/metadata/mysql/entity.go
+++ b/internal/database/metadata/mysql/entity.go
@@ -9,8 +9,8 @@ import (
 )
 
 func createEntity(ctx context.Context, sqlxCtx metadata.SqlxContext, opt metadata.CreateEntityOpt) (int, error) {
-	query := "INSERT INTO entity(name, length, description) VALUES(?, ?, ?)"
-	res, err := sqlxCtx.ExecContext(ctx, query, opt.EntityName, opt.Length, opt.Description)
+	query := "INSERT INTO entity(name, description) VALUES(?, ?)"
+	res, err := sqlxCtx.ExecContext(ctx, query, opt.EntityName, opt.Description)
 	if err != nil {
 		if er, ok := err.(*mysql.MySQLError); ok {
 			if er.Number == ER_DUP_ENTRY {
diff --git a/internal/database/metadata/mysql/schema.go b/internal/database/metadata/mysql/schema.go
index 56319a8c..b50f2a92 100644
--- a/internal/database/metadata/mysql/schema.go
+++ b/internal/database/metadata/mysql/schema.go
@@ -32,7 +32,6 @@ var META_TABLE_SCHEMAS = map[string]string{
 		CREATE TABLE entity (
 			id				INT 			NOT	NULL AUTO_INCREMENT PRIMARY KEY,
 			name        	VARCHAR(32) 	NOT	NULL,
-			length      	SMALLINT    	NOT	NULL COMMENT "feature entity value max length",
 			description 	VARCHAR(64) 	DEFAULT '',
 			create_time 	TIMESTAMP   	NOT	NULL DEFAULT CURRENT_TIMESTAMP,
 			modify_time 	TIMESTAMP   	NOT	NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
diff --git a/internal/database/metadata/postgres/entity.go b/internal/database/metadata/postgres/entity.go
index e7cdf7ce..a67d2a67 100644
--- a/internal/database/metadata/postgres/entity.go
+++ b/internal/database/metadata/postgres/entity.go
@@ -11,8 +11,8 @@ import (
 
 func createEntity(ctx context.Context, sqlxCtx metadata.SqlxContext, opt metadata.CreateEntityOpt) (int, error) {
 	var entityID int
-	query := "INSERT INTO entity(name, length, description) VALUES($1, $2, $3) returning id"
-	err := sqlxCtx.GetContext(ctx, &entityID, query, opt.EntityName, opt.Length, opt.Description)
+	query := "INSERT INTO entity(name, description) VALUES($1, $2) returning id"
+	err := sqlxCtx.GetContext(ctx, &entityID, query, opt.EntityName, opt.Description)
 	if er, ok := err.(*pq.Error); ok {
 		if er.Code == pgerrcode.UniqueViolation {
 			return 0, fmt.Errorf("entity %s already exists", opt.EntityName)
diff --git a/internal/database/metadata/postgres/schema.go b/internal/database/metadata/postgres/schema.go
index b976b440..3ff4a79a 100644
--- a/internal/database/metadata/postgres/schema.go
+++ b/internal/database/metadata/postgres/schema.go
@@ -53,13 +53,11 @@ var META_TABLE_SCHEMAS = map[string]string{
 		CREATE TABLE entity (
 			id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
 			name        VARCHAR(32) NOT     NULL,
-			length      SMALLINT    NOT     NULL,
 			description VARCHAR(64) DEFAULT '',
 			create_time TIMESTAMP   NOT     NULL DEFAULT CURRENT_TIMESTAMP,
 			modify_time TIMESTAMP   NOT     NULL DEFAULT CURRENT_TIMESTAMP,
 			UNIQUE (name)
 		);
-		COMMENT ON COLUMN entity.length IS 'feature entity value max length';
 		`,
 	"feature_group_revision": `
 		CREATE TABLE feature_group_revision (
diff --git a/internal/database/metadata/sqlite/entity.go b/internal/database/metadata/sqlite/entity.go
index ba7cf195..4f719da9 100644
--- a/internal/database/metadata/sqlite/entity.go
+++ b/internal/database/metadata/sqlite/entity.go
@@ -10,8 +10,8 @@ import (
 )
 
 func createEntity(ctx context.Context, sqlxCtx metadata.SqlxContext, opt metadata.CreateEntityOpt) (int, error) {
-	query := "INSERT INTO entity(name, length, description) VALUES(?, ?, ?)"
-	res, err := sqlxCtx.ExecContext(ctx, query, opt.EntityName, opt.Length, opt.Description)
+	query := "INSERT INTO entity(name, description) VALUES(?, ?)"
+	res, err := sqlxCtx.ExecContext(ctx, query, opt.EntityName, opt.Description)
 	if err != nil {
 		if er, ok := err.(sqlite3.Error); ok {
 			if er.ExtendedCode == sqlite3.ErrConstraintUnique {
diff --git a/internal/database/metadata/sqlite/schema.go b/internal/database/metadata/sqlite/schema.go
index 65cea474..29f969bb 100644
--- a/internal/database/metadata/sqlite/schema.go
+++ b/internal/database/metadata/sqlite/schema.go
@@ -43,7 +43,6 @@ var META_TABLE_SCHEMAS = map[string]string{
 		CREATE TABLE entity (
 			id				INTEGER 		NOT	NULL PRIMARY KEY AUTOINCREMENT,
 			name        	VARCHAR(32) 	NOT	NULL,
-			length      	SMALLINT    	NOT	NULL,
 			description 	VARCHAR(64) 	DEFAULT '',
 			create_time 	TIMESTAMP   	NOT	NULL DEFAULT CURRENT_TIMESTAMP,
 			modify_time 	TIMESTAMP   	NOT	NULL DEFAULT CURRENT_TIMESTAMP,
diff --git a/internal/database/offline/sqlutil/join_helper.go b/internal/database/offline/sqlutil/join_helper.go
index aa3b00f9..aadc3be4 100644
--- a/internal/database/offline/sqlutil/join_helper.go
+++ b/internal/database/offline/sqlutil/join_helper.go
@@ -166,8 +166,12 @@ func prepareTableSchema(dbOpt dbutil.DBOpt, entity types.Entity, tableName strin
 		entityType = "STRING"
 		valueType = "STRING"
 		qtTableName = fmt.Sprintf("%s.%s", *dbOpt.DatasetID, qt(tableName))
+	case types.BackendMySQL:
+		entityType = "VARCHAR(255)"
+		valueType = "TEXT"
+		qtTableName = qt(tableName)
 	default:
-		entityType = fmt.Sprintf("VARCHAR(%d)", entity.Length)
+		entityType = "TEXT"
 		valueType = "TEXT"
 		qtTableName = qt(tableName)
 	}
diff --git a/internal/database/online/sqlutil/util.go b/internal/database/online/sqlutil/util.go
index d54bc687..7b3a89b4 100644
--- a/internal/database/online/sqlutil/util.go
+++ b/internal/database/online/sqlutil/util.go
@@ -25,10 +25,8 @@ func CreateStreamTableSchema(ctx context.Context, tableName string, entity *type
 	)
 	switch backend {
 	case types.BackendMySQL:
-		entityFormat = fmt.Sprintf("`%s` VARCHAR(%d) PRIMARY KEY", entity.Name, entity.Length)
-	case types.BackendPostgres:
-		entityFormat = fmt.Sprintf(`"%s" VARCHAR(%d) PRIMARY KEY`, entity.Name, entity.Length)
-	case types.BackendCassandra, types.BackendSQLite:
+		entityFormat = fmt.Sprintf("`%s` VARCHAR(255) PRIMARY KEY", entity.Name)
+	case types.BackendPostgres, types.BackendCassandra, types.BackendSQLite:
 		entityFormat = fmt.Sprintf(`"%s" TEXT PRIMARY KEY`, entity.Name)
 	default:
 		return "", errdefs.InvalidAttribute(fmt.Errorf("backend %s not support", backend))
diff --git a/oomcli/cmd/register_entity.go b/oomcli/cmd/register_entity.go
index 4d37e349..24da9ba0 100644
--- a/oomcli/cmd/register_entity.go
+++ b/oomcli/cmd/register_entity.go
@@ -33,8 +33,5 @@ func init() {
 
 	flags := registerEntityCmd.Flags()
 
-	flags.IntVarP(&registerEntityOpt.Length, "length", "l", 0, "entity value length")
-	_ = registerEntityCmd.MarkFlagRequired("length")
-
 	flags.StringVarP(&registerEntityOpt.Description, "description", "d", "", "entity description")
 }
diff --git a/oomcli/cmd/types.go b/oomcli/cmd/types.go
index 539fcdfa..d46438e0 100644
--- a/oomcli/cmd/types.go
+++ b/oomcli/cmd/types.go
@@ -10,7 +10,6 @@ import (
 type FlattenEntity struct {
 	ID          int    `oomcli:"ID"`
 	Name        string `oomcli:"NAME"`
-	Length      int    `oomcli:"LENGTH"`
 	Description string `oomcli:"DESCRIPTION,truncate"`
 
 	CreateTime time.Time `oomcli:"CREATE-TIME,wide"`
@@ -66,7 +65,6 @@ func parseTokenLists(i interface{}) (headerTokens TokenList, dataTokens []TokenL
 			tokens, err = parseTokens(FlattenEntity{
 				ID:          e.ID,
 				Name:        e.Name,
-				Length:      e.Length,
 				Description: e.Description,
 				CreateTime:  e.CreateTime,
 				ModifyTime:  e.ModifyTime,
diff --git a/pkg/oomstore/apply.go b/pkg/oomstore/apply.go
index e819bc99..1be400bd 100644
--- a/pkg/oomstore/apply.go
+++ b/pkg/oomstore/apply.go
@@ -60,7 +60,6 @@ func (s *OomStore) applyEntity(ctx context.Context, tx metadata.DBStore, newEnti
 		_, err = tx.CreateEntity(ctx, metadata.CreateEntityOpt{
 			CreateEntityOpt: types.CreateEntityOpt{
 				EntityName:  newEntity.Name,
-				Length:      newEntity.Length,
 				Description: newEntity.Description,
 			},
 		})
@@ -305,7 +304,6 @@ func buildApplyEntity(entity apply.Entity) apply.Entity {
 	return apply.Entity{
 		Kind:        entity.Kind,
 		Name:        entity.Name,
-		Length:      entity.Length,
 		Description: entity.Description,
 	}
 }
diff --git a/pkg/oomstore/types/apply/apply.go b/pkg/oomstore/types/apply/apply.go
index f0f73bf4..16637c34 100644
--- a/pkg/oomstore/types/apply/apply.go
+++ b/pkg/oomstore/types/apply/apply.go
@@ -136,7 +136,6 @@ func (g *Group) Validate() error {
 type Entity struct {
 	Kind        string `mapstructure:"kind" yaml:"kind"`
 	Name        string `mapstructure:"name" yaml:"name"`
-	Length      int    `mapstructure:"length" yaml:"length"`
 	Description string `mapstructure:"description" yaml:"description"`
 
 	Groups []Group `mapstructure:"groups" yaml:"groups,omitempty"`
@@ -158,7 +157,6 @@ func FromEntityList(entities types.EntityList, groups *GroupItems) (items Entity
 		items.Items = append(items.Items, Entity{
 			Kind:        "Entity",
 			Name:        entity.Name,
-			Length:      entity.Length,
 			Description: entity.Description,
 			Groups: groups.Filter(func(g Group) bool {
 				return g.EntityName == entity.Name
diff --git a/pkg/oomstore/types/entity.go b/pkg/oomstore/types/entity.go
index f893b455..81eada28 100644
--- a/pkg/oomstore/types/entity.go
+++ b/pkg/oomstore/types/entity.go
@@ -5,9 +5,8 @@ import (
 )
 
 type Entity struct {
-	ID     int    `db:"id"`
-	Name   string `db:"name"`
-	Length int    `db:"length"`
+	ID   int    `db:"id"`
+	Name string `db:"name"`
 
 	Description string    `db:"description"`
 	CreateTime  time.Time `db:"create_time"`
diff --git a/pkg/oomstore/types/options.go b/pkg/oomstore/types/options.go
index e05bc4ad..732c8037 100644
--- a/pkg/oomstore/types/options.go
+++ b/pkg/oomstore/types/options.go
@@ -20,7 +20,6 @@ type UpdateFeatureOpt struct {
 
 type CreateEntityOpt struct {
 	EntityName  string
-	Length      int
 	Description string
 }
 


Test patch:
diff --git a/internal/database/dbutil/schema_test.go b/internal/database/dbutil/schema_test.go
index 37846274..36bb6270 100644
--- a/internal/database/dbutil/schema_test.go
+++ b/internal/database/dbutil/schema_test.go
@@ -35,15 +35,12 @@ func TestBuildSchema(t *testing.T) {
 			description: "postgres schema",
 			backend:     types.BackendPostgres,
 			tableName:   "user",
-			entity: &types.Entity{
-				Name:   "user_id",
-				Length: 32,
-			},
-			features: features,
+			entity:      &types.Entity{Name: "user_id"},
+			features:    features,
 
 			want: `
 CREATE TABLE "user" (
-	"user_id" VARCHAR(32),
+	"user_id" TEXT,
 	"age" bigint,
 	"gender" text
 )`,
@@ -53,15 +50,12 @@ CREATE TABLE "user" (
 			description: "mysql schema",
 			backend:     types.BackendMySQL,
 			tableName:   "user",
-			entity: &types.Entity{
-				Name:   "user_id",
-				Length: 32,
-			},
-			features: features,
+			entity:      &types.Entity{Name: "user_id"},
+			features:    features,
 
 			want: "\n" +
 				"CREATE TABLE `user` (\n" +
-				"	`user_id` VARCHAR(32),\n" +
+				"	`user_id` VARCHAR(255),\n" +
 				"	`age` bigint,\n" +
 				"	`gender` text\n)",
 			wantErr: nil,
diff --git a/internal/database/metadata/informer/informer_test.go b/internal/database/metadata/informer/informer_test.go
index 9c5b2a4e..1dc0b638 100644
--- a/internal/database/metadata/informer/informer_test.go
+++ b/internal/database/metadata/informer/informer_test.go
@@ -14,9 +14,8 @@ import (
 
 func sampleCache() *informer.Cache {
 	entity := types.Entity{
-		ID:     1,
-		Length: 10,
-		Name:   "entity",
+		ID:   1,
+		Name: "entity",
 	}
 	group := types.Group{
 		ID:       100,
diff --git a/internal/database/metadata/test_impl/entity.go b/internal/database/metadata/test_impl/entity.go
index 8da7b038..cd23c45f 100644
--- a/internal/database/metadata/test_impl/entity.go
+++ b/internal/database/metadata/test_impl/entity.go
@@ -20,7 +20,6 @@ func TestCreateEntity(t *testing.T, prepareStore PrepareStoreFn, destroyStore De
 	opt := metadata.CreateEntityOpt{
 		CreateEntityOpt: types.CreateEntityOpt{
 			EntityName:  "device",
-			Length:      32,
 			Description: "description",
 		},
 	}
@@ -30,7 +29,6 @@ func TestCreateEntity(t *testing.T, prepareStore PrepareStoreFn, destroyStore De
 	_, err = store.CreateEntity(ctx, metadata.CreateEntityOpt{
 		CreateEntityOpt: types.CreateEntityOpt{
 			EntityName:  "device",
-			Length:      32,
 			Description: "description",
 		},
 	})
@@ -46,7 +44,6 @@ func TestGetEntity(t *testing.T, prepareStore PrepareStoreFn, destroyStore Destr
 	opt := metadata.CreateEntityOpt{
 		CreateEntityOpt: types.CreateEntityOpt{
 			EntityName:  "device",
-			Length:      32,
 			Description: "description",
 		},
 	}
@@ -57,7 +54,6 @@ func TestGetEntity(t *testing.T, prepareStore PrepareStoreFn, destroyStore Destr
 	entity, err := store.GetEntity(ctx, id)
 	require.NoError(t, err)
 	require.Equal(t, opt.EntityName, entity.Name)
-	require.Equal(t, opt.Length, entity.Length)
 	require.Equal(t, opt.Description, entity.Description)
 
 	_, err = store.GetEntity(ctx, 0)
@@ -73,7 +69,6 @@ func TestUpdateEntity(t *testing.T, prepareStore PrepareStoreFn, destroyStore De
 	id, err := store.CreateEntity(ctx, metadata.CreateEntityOpt{
 		CreateEntityOpt: types.CreateEntityOpt{
 			EntityName:  "device",
-			Length:      32,
 			Description: "description",
 		},
 	})
@@ -109,7 +104,6 @@ func TestListEntity(t *testing.T, prepareStore PrepareStoreFn, destroyStore Dest
 	_, err = store.CreateEntity(ctx, metadata.CreateEntityOpt{
 		CreateEntityOpt: types.CreateEntityOpt{
 			EntityName:  "device",
-			Length:      32,
 			Description: "description",
 		},
 	})
@@ -122,7 +116,6 @@ func TestListEntity(t *testing.T, prepareStore PrepareStoreFn, destroyStore Dest
 	_, err = store.CreateEntity(ctx, metadata.CreateEntityOpt{
 		CreateEntityOpt: types.CreateEntityOpt{
 			EntityName:  "user",
-			Length:      16,
 			Description: "description",
 		},
 	})
diff --git a/internal/database/metadata/test_impl/feature.go b/internal/database/metadata/test_impl/feature.go
index 2a9b7c08..9f3b8129 100644
--- a/internal/database/metadata/test_impl/feature.go
+++ b/internal/database/metadata/test_impl/feature.go
@@ -17,7 +17,6 @@ func prepareEntityAndGroup(t *testing.T, ctx context.Context, store metadata.Sto
 	entityID, err := store.CreateEntity(ctx, metadata.CreateEntityOpt{
 		CreateEntityOpt: types.CreateEntityOpt{
 			EntityName:  "device",
-			Length:      32,
 			Description: "description",
 		},
 	})
diff --git a/internal/database/metadata/test_impl/group.go b/internal/database/metadata/test_impl/group.go
index 493a820d..085c5846 100644
--- a/internal/database/metadata/test_impl/group.go
+++ b/internal/database/metadata/test_impl/group.go
@@ -15,7 +15,6 @@ func prepareEntity(t *testing.T, ctx context.Context, store metadata.Store, name
 	entityID, err := store.CreateEntity(ctx, metadata.CreateEntityOpt{
 		CreateEntityOpt: types.CreateEntityOpt{
 			EntityName:  name,
-			Length:      32,
 			Description: "description",
 		},
 	})
diff --git a/internal/database/metadata/test_impl/revision.go b/internal/database/metadata/test_impl/revision.go
index fbea169f..6f0568a8 100644
--- a/internal/database/metadata/test_impl/revision.go
+++ b/internal/database/metadata/test_impl/revision.go
@@ -357,7 +357,6 @@ func prepareRevisions(t *testing.T, ctx context.Context, store metadata.Store) (
 	entityID, err := store.CreateEntity(ctx, metadata.CreateEntityOpt{
 		CreateEntityOpt: types.CreateEntityOpt{
 			EntityName:  "device",
-			Length:      32,
 			Description: "description",
 		},
 	})
diff --git a/internal/database/offline/test_impl/create_table.go b/internal/database/offline/test_impl/create_table.go
index 33573366..0058a10c 100644
--- a/internal/database/offline/test_impl/create_table.go
+++ b/internal/database/offline/test_impl/create_table.go
@@ -15,10 +15,7 @@ func TestCreateTable(t *testing.T, prepareStore PrepareStoreFn, destroyStore Des
 	defer store.Close()
 
 	tableName := "new_table"
-	entity := types.Entity{
-		Name:   "device",
-		Length: 16,
-	}
+	entity := types.Entity{Name: "device"}
 	features := []*types.Feature{
 		{
 			Name:      "price",
diff --git a/internal/database/offline/test_impl/import.go b/internal/database/offline/test_impl/import.go
index 87a9fc8f..3d613e29 100644
--- a/internal/database/offline/test_impl/import.go
+++ b/internal/database/offline/test_impl/import.go
@@ -19,10 +19,7 @@ func TestImport(t *testing.T, prepareStore PrepareStoreFn, destroyStore DestroyS
 	ctx, store := prepareStore(t)
 	defer store.Close()
 
-	entity := types.Entity{
-		Name:   "device",
-		Length: 16,
-	}
+	entity := types.Entity{Name: "device"}
 	snapshotTable := "offline_1_1"
 
 	opt := offline.ImportOpt{
diff --git a/internal/database/offline/test_impl/join.go b/internal/database/offline/test_impl/join.go
index 9282cfd2..fb550314 100644
--- a/internal/database/offline/test_impl/join.go
+++ b/internal/database/offline/test_impl/join.go
@@ -23,10 +23,7 @@ func TestJoin(t *testing.T, prepareStore PrepareStoreFn, destroyStore DestroySto
 	ctx, store := prepareStore(t)
 	defer store.Close()
 
-	entity := &types.Entity{
-		Name:   "device",
-		Length: 10,
-	}
+	entity := &types.Entity{Name: "device"}
 	unixMilli := &types.Feature{
 		Name:      "unix_milli",
 		ValueType: types.Int64,
diff --git a/internal/database/offline/test_impl/push.go b/internal/database/offline/test_impl/push.go
index 7063cb9e..c2b142b2 100644
--- a/internal/database/offline/test_impl/push.go
+++ b/internal/database/offline/test_impl/push.go
@@ -17,9 +17,8 @@ func TestPush(t *testing.T, prepareStore PrepareStoreFn, destroyStore DestroySto
 	defer store.Close()
 
 	entity := types.Entity{
-		ID:     18,
-		Name:   "user",
-		Length: 10,
+		ID:   18,
+		Name: "user",
 	}
 	group := types.Group{
 		ID:       1,
diff --git a/internal/database/offline/test_impl/snapshot.go b/internal/database/offline/test_impl/snapshot.go
index 21299a94..37701b37 100644
--- a/internal/database/offline/test_impl/snapshot.go
+++ b/internal/database/offline/test_impl/snapshot.go
@@ -21,11 +21,8 @@ func TestSnapshot(t *testing.T, prepareStore PrepareStoreFn, destroyStore Destro
 	defer store.Close()
 
 	group := &types.Group{
-		ID: 1,
-		Entity: &types.Entity{
-			Name:   "device",
-			Length: 10,
-		},
+		ID:     1,
+		Entity: &types.Entity{Name: "device"},
 	}
 	unixMilli := &types.Feature{
 		Name:      "unix_milli",
diff --git a/internal/database/offline/test_impl/util.go b/internal/database/offline/test_impl/util.go
index 8a18f29f..47396ed8 100644
--- a/internal/database/offline/test_impl/util.go
+++ b/internal/database/offline/test_impl/util.go
@@ -22,10 +22,7 @@ func buildTestSnapshotTable(
 	snapshotTable string,
 	source *offline.CSVSource,
 ) {
-	entity := &types.Entity{
-		Name:   "device",
-		Length: 10,
-	}
+	entity := &types.Entity{Name: "device"}
 	header := []string{"device"}
 	for _, f := range features {
 		header = append(header, f.Name)
diff --git a/internal/database/online/test_impl/stream.go b/internal/database/online/test_impl/stream.go
index 7e1c99c2..4850deba 100644
--- a/internal/database/online/test_impl/stream.go
+++ b/internal/database/online/test_impl/stream.go
@@ -19,9 +19,8 @@ var simpleStreamData StreamData
 
 func init() {
 	entity := types.Entity{
-		ID:     1,
-		Name:   "user",
-		Length: 16,
+		ID:   1,
+		Name: "user",
 	}
 
 	group1 := &types.Group{
diff --git a/internal/database/online/test_impl/util.go b/internal/database/online/test_impl/util.go
index 466e38ad..fb3b9840 100644
--- a/internal/database/online/test_impl/util.go
+++ b/internal/database/online/test_impl/util.go
@@ -83,7 +83,7 @@ func init() {
 					Category: types.CategoryBatch,
 				},
 			},
-			Entity: &types.Entity{ID: 5, Name: "user", Length: 4},
+			Entity: &types.Entity{ID: 5, Name: "user"},
 			Data: []types.ExportRecord{
 				[]interface{}{"3215", int64(18), "F", 1.1, true, time.Now()},
 				[]interface{}{"3216", int64(29), nil, 2.0, false, time.Now()},
@@ -106,11 +106,11 @@ func init() {
 		}
 
 		revision := &types.Revision{ID: 9, GroupID: 2, Group: &types.Group{ID: 2, Category: types.CategoryBatch}}
-		entity := &types.Entity{ID: 5, Name: "user", Length: 5}
+		entity := &types.Entity{ID: 5, Name: "user"}
 		var data []types.ExportRecord
 
 		for i := 0; i < 100; i++ {
-			record := []interface{}{dbutil.RandString(entity.Length), rand.Float64()}
+			record := []interface{}{dbutil.RandString(10), rand.Float64()}
 			data = append(data, record)
 		}
 		SampleMedium = Sample{features, revision, entity, data}
diff --git a/oomagent/test/data/driver_stats.yaml b/oomagent/test/data/driver_stats.yaml
index 3eb8401e..48cfa4a8 100644
--- a/oomagent/test/data/driver_stats.yaml
+++ b/oomagent/test/data/driver_stats.yaml
@@ -1,7 +1,6 @@
 ---
 kind: Entity
 name: driver
-length: 2
 groups:
   - name: driver_stats
     category: batch
diff --git a/oomagent/test/data/fraud_detection.yaml b/oomagent/test/data/fraud_detection.yaml
index 7edcf39b..1244259f 100644
--- a/oomagent/test/data/fraud_detection.yaml
+++ b/oomagent/test/data/fraud_detection.yaml
@@ -1,6 +1,5 @@
 kind: Entity
 name: user
-length: 12
 description: 'user id'
 groups:
 - name: account
diff --git a/oomcli/test/test_apply_entity.sh b/oomcli/test/test_apply_entity.sh
index cfe252fb..61bb744c 100755
--- a/oomcli/test/test_apply_entity.sh
+++ b/oomcli/test/test_apply_entity.sh
@@ -8,7 +8,6 @@ apply_single_complex_entity() {
     cat <<EOF | oomcli apply -f /dev/stdin
 kind: Entity
 name: user
-length: 8
 description: 'description'
 groups:
 - name: device
@@ -34,8 +33,8 @@ groups:
 EOF
 
     entity_expected='
-ID,NAME,LENGTH,DESCRIPTION
-1,user,8,description
+ID,NAME,DESCRIPTION
+1,user,description
 '
     entity_actual=$(oomcli get meta entity -o csv)
     assert_eq "apply_single_complex_entity: check entity" "$(sort <<< "$entity_expected")" "$(sort <<< "$entity_actual")"
@@ -66,7 +65,6 @@ apply_multiple_files_of_entity() {
     cat <<EOF | oomcli apply -f /dev/stdin
 kind: Entity
 name: user
-length: 8
 description: 'description'
 groups:
 - name: student
@@ -75,21 +73,19 @@ groups:
 ---
 kind: Entity
 name: device
-length: 16
 description: 'description'
 ---
 kind: Entity
 name: test
-length: 32
 description: 'description'
 EOF
 
 
   entity_expected='
-ID,NAME,LENGTH,DESCRIPTION
-1,user,8,description
-2,device,16,description
-3,test,32,description
+ID,NAME,DESCRIPTION
+1,user,description
+2,device,description
+3,test,description
 '
     entity_actual=$(oomcli get meta entity -o csv)
     assert_eq "apply_multiple_files_of_entity: oomcli get meta entity" "$entity_expected" "$entity_actual"
@@ -110,7 +106,6 @@ apply_entity_items() {
 items:
   - kind: Entity
     name: user
-    length: 8
     description: user ID
     groups:
       - name: account
@@ -138,7 +133,6 @@ items:
             description: transaction_count_30d description
   - kind: Entity
     name: device
-    length: 8
     description: device info
     groups:
       - name: phone
@@ -154,9 +148,9 @@ items:
 EOF
 
       entity_expected='
-ID,NAME,LENGTH,DESCRIPTION
-1,user,8,user ID
-2,device,8,device info
+ID,NAME,DESCRIPTION
+1,user,user ID
+2,device,device info
 '
       entity_actual=$(oomcli get meta entity -o csv)
       assert_eq "apply_entity_items: oomcli apply mutiple entity: check entity" "$(sort <<< "$entity_expected")" "$(sort <<< "$entity_actual")"
diff --git a/oomcli/test/test_apply_feature.sh b/oomcli/test/test_apply_feature.sh
index bdf15553..de5f2494 100755
--- a/oomcli/test/test_apply_feature.sh
+++ b/oomcli/test/test_apply_feature.sh
@@ -10,7 +10,6 @@ apply_multiple_files_of_feature() {
     cat <<EOF | oomcli apply -f /dev/stdin
 kind: Entity
 name: user
-length: 8
 description: 'description'
 ---
 kind: Group
@@ -49,7 +48,6 @@ apply_feature_items() {
     cat <<EOF | oomcli apply -f /dev/stdin
 kind: Entity
 name: user
-length: 8
 description: user ID
 ---
 kind: Group
diff --git a/oomcli/test/test_apply_group.sh b/oomcli/test/test_apply_group.sh
index d73b40f4..ca59442f 100755
--- a/oomcli/test/test_apply_group.sh
+++ b/oomcli/test/test_apply_group.sh
@@ -10,7 +10,6 @@ apply_single_complex_group() {
     cat <<EOF | oomcli apply -f /dev/stdin
 kind: Entity
 name: user
-length: 8
 description: 'description'
 ---
 kind: Group
@@ -54,7 +53,6 @@ apply_multiple_files_of_group() {
     cat <<EOF | oomcli apply -f /dev/stdin
 kind: Entity
 name: user
-length: 8
 description: 'description'
 ---
 kind: Group
@@ -86,12 +84,10 @@ apply_group_items() {
     cat <<EOF | oomcli apply -f /dev/stdin
 kind: Entity
 name: user
-length: 8
 description: 'description'
 ---
 kind: Entity
 name: device
-length: 8
 description: 'description'
 ---
 items:
diff --git a/oomcli/test/test_get_meta_entity.sh b/oomcli/test/test_get_meta_entity.sh
index ffac5278..f4905fa2 100755
--- a/oomcli/test/test_get_meta_entity.sh
+++ b/oomcli/test/test_get_meta_entity.sh
@@ -7,19 +7,19 @@ register_features
 import_sample > /dev/null
 
 case='oomcli get meta entity works'
-expected='ID,NAME,LENGTH,DESCRIPTION,CREATE-TIME,MODIFY-TIME
-1,device,32,device,2021-10-19T06:56:07Z,2021-10-19T06:56:07Z
-2,user,64,user,2021-10-19T06:56:07Z,2021-10-19T06:56:07Z
+expected='ID,NAME,DESCRIPTION,CREATE-TIME,MODIFY-TIME
+1,device,device,2021-10-19T06:56:07Z,2021-10-19T06:56:07Z
+2,user,user,2021-10-19T06:56:07Z,2021-10-19T06:56:07Z
 '
 actual=$(oomcli get meta entity -o csv)
-ignore_time() { cut -d ',' -f 1-4 <<<"$1"; }
+ignore_time() { cut -d ',' -f 1-3 <<<"$1"; }
 assert_eq "$case" "$(ignore_time "$expected" | sort)" "$(ignore_time "$actual" | sort)"
 
 
 case='oomcli get simplified meta entity works'
-expected='ID,NAME,LENGTH,DESCRIPTION
-1,device,32,device
-2,user,64,user
+expected='ID,NAME,DESCRIPTION
+1,device,device
+2,user,user
 '
 actual=$(oomcli get meta entity -o csv)
 assert_eq "$case" "$(sort <<< "$expected")" "$(sort <<< "$actual")"
@@ -28,7 +28,6 @@ case='oomcli get meta entity -o yaml: one entity'
 expected='
 kind: Entity
 name: device
-length: 32
 description: device
 groups:
     - name: phone
@@ -51,7 +50,6 @@ expected='
 items:
     - kind: Entity
       name: device
-      length: 32
       description: device
       groups:
         - name: phone
@@ -66,7 +64,6 @@ items:
               description: model
     - kind: Entity
       name: user
-      length: 64
       description: user
       groups:
         - name: student
diff --git a/oomcli/test/test_update_entity.sh b/oomcli/test/test_update_entity.sh
index 480f9918..e4ef0699 100755
--- a/oomcli/test/test_update_entity.sh
+++ b/oomcli/test/test_update_entity.sh
@@ -9,8 +9,8 @@ import_sample > /dev/null
 case='oomcli update entity works'
 oomcli update entity device --description "new description"
 expected='
-ID,NAME,LENGTH,DESCRIPTION
-1,device,32,new description
+ID,NAME,DESCRIPTION
+1,device,new description
 '
 actual=$(oomcli get meta entity device -o csv)
 assert_eq "$case" "$expected" "$actual"
diff --git a/oomcli/test/util.sh b/oomcli/test/util.sh
index 4c2f4b73..059a4888 100644
--- a/oomcli/test/util.sh
+++ b/oomcli/test/util.sh
@@ -52,8 +52,8 @@ assert_eq() {
 
 # register features for the sample data
 register_features() {
-    oomcli register entity device --length 32     --description "device"
-    oomcli register entity user   --length 64     --description "user"
+    oomcli register entity device --description "device"
+    oomcli register entity user   --description "user"
 
     oomcli register group phone      --entity device --category "batch"  --description "phone"
     oomcli register group student    --entity user   --category "batch"  --description "student"
diff --git a/pkg/oomstore/apply_test.go b/pkg/oomstore/apply_test.go
index ca696f21..745fe01f 100644
--- a/pkg/oomstore/apply_test.go
+++ b/pkg/oomstore/apply_test.go
@@ -24,7 +24,6 @@ func TestBuildApplyStage(t *testing.T) {
 			opt: apply.ApplyOpt{R: strings.NewReader(`
 # kind: Entity
 name: user
-length: 8
 description: 'User ID'
 `)},
 			wantStage: nil,
@@ -35,7 +34,6 @@ description: 'User ID'
 			opt: apply.ApplyOpt{R: strings.NewReader(`
 kind: Entit
 name: user
-length: 8
 description: 'description'
 `)},
 			wantStage: nil,
@@ -46,7 +44,6 @@ description: 'description'
 			opt: apply.ApplyOpt{R: strings.NewReader(`
 kind: Entity
 name: user
-length: 8
 description: 'description'
 `)},
 			wantStage: &apply.ApplyStage{
@@ -54,7 +51,6 @@ description: 'description'
 					{
 						Kind:        "Entity",
 						Name:        "user",
-						Length:      8,
 						Description: "description",
 					},
 				},
@@ -68,7 +64,6 @@ description: 'description'
 			opt: apply.ApplyOpt{R: strings.NewReader(`
 kind: Entity
 name: user
-length: 8
 description: 'description'
 ---
 kind: Group
@@ -102,7 +97,6 @@ description: 'description'
 					{
 						Kind:        "Entity",
 						Name:        "user",
-						Length:      8,
 						Description: "description",
 					},
 				}, NewGroups: []apply.Group{
@@ -192,7 +186,6 @@ features:
 			opt: apply.ApplyOpt{R: strings.NewReader(`
 kind: Entity
 name: user
-length: 8
 description: 'description'
 groups:
 - name: device
@@ -221,7 +214,6 @@ groups:
 					{
 						Kind:        "Entity",
 						Name:        "user",
-						Length:      8,
 						Description: "description",
 					},
 				},
@@ -447,7 +439,6 @@ items:
 items:
     - kind: Entity
       name: user
-      length: 8
       description: user ID
       groups:
         - name: account
@@ -475,7 +466,6 @@ items:
               description: transaction_count_30d description
     - kind: Entity
       name: device
-      length: 8
       description: device info
       groups:
         - name: phone
@@ -495,13 +485,11 @@ items:
 					{
 						Kind:        "Entity",
 						Name:        "user",
-						Length:      8,
 						Description: "user ID",
 					},
 					{
 						Kind:        "Entity",
 						Name:        "device",
-						Length:      8,
 						Description: "device info",
 					},
 				},
diff --git a/pkg/oomstore/join_test.go b/pkg/oomstore/join_test.go
index 51b6b2bb..5f505f29 100644
--- a/pkg/oomstore/join_test.go
+++ b/pkg/oomstore/join_test.go
@@ -26,8 +26,7 @@ func TestChannelJoin(t *testing.T) {
 	consistentFeatures := prepareFeatures(true, true)
 
 	entity := types.Entity{
-		Name:   "device",
-		Length: 10,
+		Name: "device",
 	}
 	revisions := types.RevisionList{
 		{
diff --git a/sdk/python/src/test/test_client.py b/sdk/python/src/test/test_client.py
index 1e3d659f..24ec65ab 100644
--- a/sdk/python/src/test/test_client.py
+++ b/sdk/python/src/test/test_client.py
@@ -25,7 +25,6 @@ class Data:
             f.write(
                 """kind: Entity
 name: user
-length: 8
 description: "user ID"
 groups:
   - name: account