Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# Additional tools
.clover/
.mvn/

# OSX files
**/.DS_Store
Expand Down
6 changes: 6 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# suppresses the warning:
# Direct modification of testCompileSourceRoots through add() is deprecated and will not work in Maven 4.0.0. Please use the add/remove methods instead.
# If you're using a plugin that causes this warning, please upgrade to the latest version and report an issue if the warning persists.
# To disable these warnings, set -Dmaven.project.sourceRoots.warningsDisabled=true on the command line, in the .mvn/maven.config file,
# or in project POM properties.
-Dmaven.project.sourceRoots.warningsDisabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,16 @@
*/
public final class ArrayOfStringsSummary implements UpdatableSummary<String[]> {

private String[] stringArr = null;
private String[] stringArr = new String[] {}; //empty string array;

/**
* No argument constructor.
*/
ArrayOfStringsSummary() { //required for ArrayOfStringsSummaryFactory
stringArr = null;
}
ArrayOfStringsSummary() {} //required for ArrayOfStringsSummaryFactory

//Used by copy() and in test
ArrayOfStringsSummary(final String[] stringArr) {
this.stringArr = stringArr.clone();
checkNumNodes(stringArr.length);
update(stringArr);
}

//used by fromMemorySegment and in test
Expand Down Expand Up @@ -87,10 +84,20 @@ public final class ArrayOfStringsSummary implements UpdatableSummary<String[]> {
this.stringArr = stringArr;
}

//From UpdatableSummary

@Override
public final ArrayOfStringsSummary update(final String[] value) {
if (value == null) { stringArr = new String[] {}; }
else { stringArr = value.clone(); }
return this;
}

//From Summary

@Override
public ArrayOfStringsSummary copy() {
final ArrayOfStringsSummary nodes = new ArrayOfStringsSummary(stringArr);
return nodes;
return new ArrayOfStringsSummary(stringArr);
}

@Override
Expand All @@ -112,16 +119,6 @@ public byte[] toByteArray() {
return out;
}

//From UpdatableSummary

@Override
public ArrayOfStringsSummary update(final String[] value) {
if (stringArr == null) {
stringArr = value.clone();
}
return this;
}

//From Object

@Override
Expand All @@ -139,6 +136,8 @@ public boolean equals(final Object summary) {
return thisStr.equals(thatStr);
}

//Local

/**
* Returns the nodes array for this summary.
* @return the nodes array for this summary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,54 @@ public void checkSketch() {
String[][] strArrArr = {{"a","b"},{"c","d"},{"e","f"}};
int len = strArrArr.length;
for (int i = 0; i < len; i++) {
sketch1.update(strArrArr[i], strArrArr[i]);
sketch1.update(i, strArrArr[i]);
}
sketch1.update(strArrArr[0], strArrArr[0]); //insert duplicate
println("Sketch1");
printSummaries(sketch1.iterator());
byte[] array = sketch1.toByteArray();
MemorySegment wseg = MemorySegment.ofArray(array);

sketch1.update(0, strArrArr[0]); //insert duplicate
println("Sketch1 updated with a duplicate");
printSummaries(sketch1.iterator());

MemorySegment wseg = MemorySegment.ofArray(sketch1.toByteArray());
ArrayOfStringsTupleSketch sketch2 = new ArrayOfStringsTupleSketch(wseg);
println("Sketch2 = Sketch1 via SerDe");
printSummaries(sketch2.iterator());
checkSummaries(sketch2, sketch2);
checkSummariesEqual(sketch1, sketch2);

String[] strArr3 = {"g", "h" };
sketch2.update(strArr3, strArr3);

sketch2.update(3, strArr3);
println("Sketch2 with a new row");
printSummaries(sketch2.iterator());

TupleUnion<ArrayOfStringsSummary> union = new TupleUnion<>(new ArrayOfStringsSummarySetOperations());
union.union(sketch1);
union.union(sketch2);
CompactTupleSketch<ArrayOfStringsSummary> csk = union.getResult();
//printSummaries(csk.iterator());
println("Result of union of Sketch1, Sketch2");
printSummaries(csk.iterator());
assertEquals(csk.getRetainedEntries(), 4);

TupleIntersection<ArrayOfStringsSummary> inter =
new TupleIntersection<>(new ArrayOfStringsSummarySetOperations());
inter.intersect(sketch1);
inter.intersect(sketch2);
csk = inter.getResult();
println("Intersect Sketch1, Sketch2");
printSummaries(csk.iterator());
assertEquals(csk.getRetainedEntries(), 3);

TupleAnotB<ArrayOfStringsSummary> aNotB = new TupleAnotB<>();
aNotB.setA(sketch2);
aNotB.notB(sketch1);
csk = aNotB.getResult(true);
println("AnotB(Sketch2, Sketch1)");
printSummaries(csk.iterator());
assertEquals(csk.getRetainedEntries(), 1);

}

private static void checkSummaries(ArrayOfStringsTupleSketch sk1, ArrayOfStringsTupleSketch sk2) {
private static void checkSummariesEqual(ArrayOfStringsTupleSketch sk1, ArrayOfStringsTupleSketch sk2) {
TupleSketchIterator<ArrayOfStringsSummary> it1 = sk1.iterator();
TupleSketchIterator<ArrayOfStringsSummary> it2 = sk2.iterator();
while(it1.next() && it2.next()) {
Expand All @@ -100,6 +112,7 @@ static void printSummaries(TupleSketchIterator<ArrayOfStringsSummary> it) {
}
println("");
}
println("");
}

@Test
Expand All @@ -108,7 +121,7 @@ public void checkCopyCtor() {
String[][] strArrArr = {{"a","b"},{"c","d"},{"e","f"}};
int len = strArrArr.length;
for (int i = 0; i < len; i++) {
sk1.update(strArrArr[i], strArrArr[i]);
sk1.update(i, strArrArr[i]);
}
assertEquals(sk1.getRetainedEntries(), 3);
final ArrayOfStringsTupleSketch sk2 = sk1.copy();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.datasketches.tuple.strings;

import static org.apache.datasketches.common.Util.LS;

import org.apache.datasketches.theta.UpdatableThetaSketch;
import org.apache.datasketches.tuple.TupleSketchIterator;
import org.apache.datasketches.tuple.TupleUnion;
import org.testng.annotations.Test;

public class ArrayOfStringsSummary_Issue699 {
UpdatableThetaSketch thetaSk = UpdatableThetaSketch.builder().build();
ArrayOfStringsTupleSketch tupleSk = new ArrayOfStringsTupleSketch();
TupleUnion<ArrayOfStringsSummary> union = new TupleUnion<>(new ArrayOfStringsSummarySetOperations());

@Test
void go() {
thetaSk.update("a");
thetaSk.update("b");
thetaSk.update("c");

tupleSk.update("a", new String[] {"x", "y"});
tupleSk.update("b", new String[] {"z"});
tupleSk.update("e", new String[] {"x", "z"});

println("Print Tuple Summary before union");
printSummaries(tupleSk.iterator());

union.union(tupleSk);
union.union(thetaSk, new ArrayOfStringsSummary()); //enable this or the next
//union.union(thetaSk, new ArrayOfStringsSummary(new String[] {"u", "v"})); //optional association

println("Print Tuple Summary after union");
printSummaries(union.getResult().iterator());
}

@Test
void checkCopy() {
ArrayOfStringsSummary aoss = new ArrayOfStringsSummary();
aoss.copy(); //if null this will throw
}

@Test
void checkToByteArray() {
ArrayOfStringsSummary aoss = new ArrayOfStringsSummary();
byte[] bytes = aoss.toByteArray();
println("byte[].length = " + bytes.length);
}


static void printSummaries(TupleSketchIterator<ArrayOfStringsSummary> it) {
while (it.next()) {
String[] strArr = it.getSummary().getValue();
if (strArr.length == 0) { print("-"); } //illustrates an empty string array
for (String s : strArr) {
print(s + ", ");
}
println("");
}
println("");
}

private static void println(Object o) {
print(o + LS);
}

private static void print(Object o) {
//System.out.print(o.toString());
}
}
Loading