Browse Source

Add support for "LexicalUUIDType".

Support it by treating it the same as UUIDType.

AFAIK originally there was LexicalUUIDType and TimeUUIDType. Lexical did
simple byte-wise comparison, where Time sorted using the UUID's time
value. UUIDType was added as a convenience type (CASSANDRA-2233) which
compares using the time value for time UUIDs, else byte-wise.
LexicalUUIDType was deprecated but not removed. We still have some
schema around explicitly using the LexicalUUIDType comparator.
Muir Manders 10 năm trước cách đây
mục cha
commit
d2348c0775
2 tập tin đã thay đổi với 32 bổ sung1 xóa
  1. 31 0
      cassandra_test.go
  2. 1 1
      helpers.go

+ 31 - 0
cassandra_test.go

@@ -2126,3 +2126,34 @@ func TestManualQueryPaging(t *testing.T) {
 		t.Fatalf("expected to fetch %d rows got %d", fetched, rowsToInsert)
 		t.Fatalf("expected to fetch %d rows got %d", fetched, rowsToInsert)
 	}
 	}
 }
 }
+
+func TestLexicalUUIDType(t *testing.T) {
+	session := createSession(t)
+	defer session.Close()
+
+	if err := createTable(session, `CREATE TABLE test_lexical_uuid (
+			key     varchar,
+			column1 'org.apache.cassandra.db.marshal.LexicalUUIDType',
+			value   int,
+			PRIMARY KEY (key, column1)
+		)`); err != nil {
+		t.Fatal("create:", err)
+	}
+
+	key := TimeUUID().String()
+	column1 := TimeUUID()
+
+	err := session.Query("INSERT INTO test_lexical_uuid(key, column1, value) VALUES(?, ?, ?)", key, column1, 55).Exec()
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	var gotUUID UUID
+	if err := session.Query("SELECT column1 from test_lexical_uuid where key = ? AND column1 = ?", key, column1).Scan(&gotUUID); err != nil {
+		t.Fatal(err)
+	}
+
+	if gotUUID != column1 {
+		t.Errorf("got %s, expected %s", gotUUID, column1)
+	}
+}

+ 1 - 1
helpers.go

@@ -83,7 +83,7 @@ func getApacheCassandraType(class string) Type {
 		return TypeInt
 		return TypeInt
 	case "DateType", "TimestampType":
 	case "DateType", "TimestampType":
 		return TypeTimestamp
 		return TypeTimestamp
-	case "UUIDType":
+	case "UUIDType", "LexicalUUIDType":
 		return TypeUUID
 		return TypeUUID
 	case "UTF8Type":
 	case "UTF8Type":
 		return TypeVarchar
 		return TypeVarchar