aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2024-10-03 00:13:46 -0700
committerchrislu <chris.lu@gmail.com>2024-10-03 00:13:46 -0700
commitff479565301fad09c43a1397a52fc6aa7cd50207 (patch)
tree1ddb2170f596e0b887cf2c1f2136f38053874e93
parent11e53dd8efee7e3a52d6d11b4d908dcef3eea286 (diff)
downloadseaweedfs-ff479565301fad09c43a1397a52fc6aa7cd50207.tar.xz
seaweedfs-ff479565301fad09c43a1397a52fc6aa7cd50207.zip
add helper functions
-rw-r--r--weed/mq/schema/schema.go27
-rw-r--r--weed/mq/topic/partition.go13
2 files changed, 39 insertions, 1 deletions
diff --git a/weed/mq/schema/schema.go b/weed/mq/schema/schema.go
index 5fadf2cc2..ca31ce534 100644
--- a/weed/mq/schema/schema.go
+++ b/weed/mq/schema/schema.go
@@ -24,3 +24,30 @@ func (s *Schema) GetField(name string) (*schema_pb.Field, bool) {
field, ok := s.fieldMap[name]
return field, ok
}
+
+func TypeToString(t *schema_pb.Type) string {
+ switch t.Kind.(type) {
+ case *schema_pb.Type_ScalarType:
+ switch t.GetScalarType() {
+ case schema_pb.ScalarType_BOOL:
+ return "bool"
+ case schema_pb.ScalarType_INT32:
+ return "int32"
+ case schema_pb.ScalarType_INT64:
+ return "int64"
+ case schema_pb.ScalarType_FLOAT:
+ return "float"
+ case schema_pb.ScalarType_DOUBLE:
+ return "double"
+ case schema_pb.ScalarType_BYTES:
+ return "bytes"
+ case schema_pb.ScalarType_STRING:
+ return "string"
+ }
+ case *schema_pb.Type_ListType:
+ return "list"
+ case *schema_pb.Type_RecordType:
+ return "record"
+ }
+ return "unknown"
+}
diff --git a/weed/mq/topic/partition.go b/weed/mq/topic/partition.go
index ba1accce1..192af6c98 100644
--- a/weed/mq/topic/partition.go
+++ b/weed/mq/topic/partition.go
@@ -1,6 +1,9 @@
package topic
-import "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
+import (
+ "fmt"
+ "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
+)
const PartitionCount = 4096
@@ -81,3 +84,11 @@ func (partition Partition) Overlaps(partition2 Partition) bool {
}
return true
}
+
+func (partition Partition) String() string {
+ return fmt.Sprintf("%04d-%04d", partition.RangeStart, partition.RangeStop)
+}
+
+func ToString(partition *mq_pb.Partition) string {
+ return fmt.Sprintf("%04d-%04d", partition.RangeStart, partition.RangeStop)
+}