This is an automated email from the ASF dual-hosted git repository.

ycai pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-analytics.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 3023a20  CASSANDRA-19807: Improve the core bulk reader test system to 
match actual and expected rows by concatenating the partition keys with the 
serialized hex string instead of utf-8 string (#70)
3023a20 is described below

commit 3023a204c8ef16f886bd3dc219f7534b7edbaf2a
Author: jberragan <[email protected]>
AuthorDate: Sat Aug 3 07:51:52 2024 +0100

    CASSANDRA-19807: Improve the core bulk reader test system to match actual 
and expected rows by concatenating the partition keys with the serialized hex 
string instead of utf-8 string (#70)
    
    Patch by James Berragan; Reviewed by Francisco Guerrero, Yifan Cai for 
CASSANDRA-19807
---
 .../cassandra/spark/utils/test/TestSchema.java     | 64 +++-------------------
 .../apache/cassandra/spark/data/types/Decimal.java |  2 +-
 2 files changed, 8 insertions(+), 58 deletions(-)

diff --git 
a/cassandra-bridge/src/main/java/org/apache/cassandra/spark/utils/test/TestSchema.java
 
b/cassandra-bridge/src/main/java/org/apache/cassandra/spark/utils/test/TestSchema.java
index 0949940..31b1398 100644
--- 
a/cassandra-bridge/src/main/java/org/apache/cassandra/spark/utils/test/TestSchema.java
+++ 
b/cassandra-bridge/src/main/java/org/apache/cassandra/spark/utils/test/TestSchema.java
@@ -19,16 +19,13 @@
 
 package org.apache.cassandra.spark.utils.test;
 
-import java.math.BigDecimal;
-import java.math.RoundingMode;
+import java.nio.ByteBuffer;
 import java.nio.file.Path;
-import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -56,6 +53,7 @@ import org.apache.spark.sql.catalyst.InternalRow;
 import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.apache.cassandra.spark.utils.ByteBufferUtils;
 
 /**
  * Helper class to create and test various schemas
@@ -729,70 +727,22 @@ public final class TestSchema
                 CqlField.CqlType type = key < partitionKeys.size()
                         ? partitionKeys.get(key).type()
                         : clusteringKeys.get(key - 
partitionKeys.size()).type();
-                str.append(toString(type, get(key))).append(":");
+                str.append(toHexString(type, get(key))).append(":");
             }
             return str.toString();
         }
 
-        private String toString(CqlField.CqlType type, Object key)
+        private String toHexString(CqlField.CqlType type, Object value)
         {
-            if (key instanceof BigDecimal)
-            {
-                return ((BigDecimal) key).setScale(8, 
RoundingMode.CEILING).toPlainString();
-            }
-            else if (key instanceof Timestamp)
-            {
-                return new Date(((Timestamp) key).getTime()).toString();
-            }
-            else if (key instanceof Object[])
-            {
-                return String.format("[%s]", Arrays.stream((Object[]) key)
-                                                   .map(value -> 
toString(type, value))
-                                                   
.collect(Collectors.joining(", ")));
-            }
-            else if (key instanceof Map)
-            {
-                CqlField.CqlType innerType = getFrozenInnerType(type);
-                if (innerType instanceof CqlField.CqlMap)
-                {
-                    CqlField.CqlMap mapType = (CqlField.CqlMap) innerType;
-                    return ((Map<?, ?>) key).entrySet()
-                            .stream()
-                            .sorted((Comparator<Map.Entry<?, ?>>) (first, 
second) ->
-                                    mapType.keyType().compare(first.getKey(), 
second.getKey()))
-                            .map(Map.Entry::getValue)
-                            .collect(Collectors.toList())
-                            .toString();
-                }
-                return ((Map<?, ?>) key).entrySet().stream().collect(
-                        Collectors.toMap(entry -> toString(innerType, 
entry.getKey()),
-                                         entry -> toString(innerType, 
entry.getValue()))).toString();
-            }
-            else if (key instanceof Collection)
-            {
-                CqlField.CqlType innerType = ((CqlField.CqlCollection) 
getFrozenInnerType(type)).type();
-                return ((Collection<?>) key).stream()
-                                            .sorted(innerType)
-                                            .map(value -> toString(innerType, 
value))
-                                            
.collect(Collectors.toList()).toString();
-            }
-            return key != null ? key.toString() : "null";
-        }
-
-        private CqlField.CqlType getFrozenInnerType(CqlField.CqlType type)
-        {
-            if (type instanceof CqlField.CqlFrozen)
-            {
-                return getFrozenInnerType(((CqlField.CqlFrozen) type).inner());
-            }
-            return type;
+            ByteBuffer buf = value == null ? null : type.serialize(value);
+            return ByteBufferUtils.toHexString(buf);
         }
 
         @Override
         public String toString()
         {
             return String.format("[%s]", IntStream.range(0, values.length)
-                                                  .mapToObj(index -> 
toString(allFields.get(index).type(), values[index]))
+                                                  .mapToObj(index -> 
toHexString(allFields.get(index).type(), values[index]))
                                                   
.collect(Collectors.joining(", ")));
         }
 
diff --git 
a/cassandra-four-zero-types/src/main/java/org/apache/cassandra/spark/data/types/Decimal.java
 
b/cassandra-four-zero-types/src/main/java/org/apache/cassandra/spark/data/types/Decimal.java
index 3e309a7..670c934 100644
--- 
a/cassandra-four-zero-types/src/main/java/org/apache/cassandra/spark/data/types/Decimal.java
+++ 
b/cassandra-four-zero-types/src/main/java/org/apache/cassandra/spark/data/types/Decimal.java
@@ -95,7 +95,7 @@ public class Decimal extends NativeType
     public Object randomValue(int minCollectionSize)
     {
         BigInteger unscaledVal = new 
BigInteger(BigNumberConfig.DEFAULT.bigDecimalPrecision(), RandomUtils.RANDOM);
-        int scale = 
RandomUtils.RANDOM.nextInt(BigNumberConfig.DEFAULT.bigDecimalScale());
+        int scale = BigNumberConfig.DEFAULT.bigDecimalScale();
         return new BigDecimal(unscaledVal, scale);
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to