Skip to content

Commit 198f1c8

Browse files
committed
Feedback & Fix test failures
1 parent ba8a433 commit 198f1c8

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

core/utils/metadata-utils/src/main/java/datawave/query/util/MetadataHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,4 +2178,7 @@ public static IteratorSetting getCQRegexFilter(String regex) {
21782178
return cqRegex;
21792179
}
21802180

2181+
public AccumuloClient getAccumuloClient() {
2182+
return this.accumuloClient;
2183+
}
21812184
}

core/utils/metadata-utils/src/test/java/datawave/query/util/MetadataHelperTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datawave.query.util;
22

33
import static datawave.data.ColumnFamilyConstants.COLF_F;
4+
import static datawave.data.ColumnFamilyConstants.COLF_H;
45
import static datawave.query.util.TestUtils.createDateFrequencyMap;
56
import static org.apache.accumulo.core.iterators.LongCombiner.VAR_LEN_ENCODER;
67

@@ -105,9 +106,8 @@ private void givenMutation(String row, String columnFamily, String columnQualifi
105106
}
106107

107108
private void givenHiddenField(String row, String datatype) {
108-
Text h = new Text("h");
109109
Mutation mutation = new Mutation(row);
110-
mutation.put(h, new Text(datatype), new Value());
110+
mutation.put(COLF_H, new Text(datatype), new Value());
111111
givenMutation(mutation);
112112
}
113113

warehouse/query-core/src/test/java/datawave/query/jexl/visitors/FieldMissingFromSchemaVisitorTest.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import java.util.Collections;
88
import java.util.Set;
99

10+
import org.apache.accumulo.core.client.AccumuloClient;
11+
import org.apache.accumulo.core.client.AccumuloException;
12+
import org.apache.accumulo.core.client.AccumuloSecurityException;
13+
import org.apache.accumulo.core.client.TableExistsException;
14+
import org.apache.accumulo.core.security.Authorizations;
1015
import org.apache.commons.jexl3.parser.ASTJexlScript;
1116
import org.apache.commons.jexl3.parser.ParseException;
1217
import org.junit.Before;
@@ -16,19 +21,26 @@
1621
import com.google.common.collect.Multimap;
1722
import com.google.common.collect.Sets;
1823

24+
import datawave.accumulo.inmemory.InMemoryAccumuloClient;
25+
import datawave.accumulo.inmemory.InMemoryInstance;
1926
import datawave.query.jexl.JexlASTHelper;
2027
import datawave.query.util.MockMetadataHelper;
28+
import datawave.util.TableName;
2129

2230
public class FieldMissingFromSchemaVisitorTest {
2331

2432
// Special fields required by visitor.
2533
private Set<String> specialFields = Sets.newHashSet(ANY_FIELD, NO_FIELD);
26-
34+
private static final String[] AUTHS = {"FOO", "BAR"};
35+
private static final Set<Authorizations> AUTHS_SET = Collections.singleton(new Authorizations(AUTHS));
2736
private MockMetadataHelper helper;
2837

2938
@Before
30-
public void before() {
31-
helper = new MockMetadataHelper();
39+
public void before() throws AccumuloException, TableExistsException, AccumuloSecurityException {
40+
helper = new MockMetadataHelper(AUTHS_SET, AUTHS_SET, AUTHS_SET, getClient());
41+
if (!helper.getAccumuloClient().tableOperations().exists(TableName.METADATA)) {
42+
helper.getAccumuloClient().tableOperations().create(TableName.METADATA);
43+
}
3244
}
3345

3446
/**
@@ -314,4 +326,12 @@ private void checkEmptyDatatypeFilter(Set<String> expected, ASTJexlScript script
314326
Set<String> actual = FieldMissingFromSchemaVisitor.getNonExistentFields(helper, script, Collections.emptySet(), specialFields);
315327
assertEquals(expected, actual);
316328
}
329+
330+
private static AccumuloClient getClient() {
331+
try {
332+
return new InMemoryAccumuloClient("root", new InMemoryInstance());
333+
} catch (AccumuloSecurityException e) {
334+
throw new RuntimeException(e);
335+
}
336+
}
317337
}

warehouse/query-core/src/test/java/datawave/query/rules/FieldExistenceRuleTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,27 @@
44
import java.util.HashSet;
55
import java.util.Set;
66

7+
import org.apache.accumulo.core.client.AccumuloClient;
8+
import org.apache.accumulo.core.client.AccumuloSecurityException;
9+
import org.apache.accumulo.core.security.Authorizations;
710
import org.easymock.EasyMock;
811
import org.junit.jupiter.api.BeforeAll;
912
import org.junit.jupiter.api.BeforeEach;
1013
import org.junit.jupiter.api.Test;
1114

15+
import datawave.accumulo.inmemory.InMemoryAccumuloClient;
16+
import datawave.accumulo.inmemory.InMemoryInstance;
1217
import datawave.query.util.MetadataHelper;
1318
import datawave.query.util.MockMetadataHelper;
19+
import datawave.util.TableName;
1420

1521
public class FieldExistenceRuleTest extends ShardQueryRuleTest {
1622

1723
private static final Set<String> ALL_FIELDS = Set.of("FOO", "BAR", "BAT");
1824
private static final String ANYFIELD = "_ANYFIELD_";
19-
private static final MockMetadataHelper defaultMetadataHelper = new MockMetadataHelper();
25+
private static final String[] AUTHS = {"FOO", "BAR"};
26+
private static final Set<Authorizations> AUTHS_SET = Collections.singleton(new Authorizations(AUTHS));
27+
private static final MockMetadataHelper defaultMetadataHelper = new MockMetadataHelper(AUTHS_SET, AUTHS_SET, AUTHS_SET, getClient());
2028

2129
private final Set<String> fieldExceptions = new HashSet<>();
2230

@@ -30,6 +38,9 @@ public void setUp() throws Exception {
3038
givenRuleName(RULE_NAME);
3139
givenMetadataHelper(defaultMetadataHelper);
3240
expectRuleName(RULE_NAME);
41+
if (!defaultMetadataHelper.getAccumuloClient().tableOperations().exists(TableName.METADATA)) {
42+
defaultMetadataHelper.getAccumuloClient().tableOperations().create(TableName.METADATA);
43+
}
3344
}
3445

3546
/**
@@ -95,4 +106,12 @@ protected ShardQueryRule getNewRule() {
95106
rule.setSpecialFields(fieldExceptions);
96107
return rule;
97108
}
109+
110+
private static AccumuloClient getClient() {
111+
try {
112+
return new InMemoryAccumuloClient("root", new InMemoryInstance());
113+
} catch (AccumuloSecurityException e) {
114+
throw new RuntimeException(e);
115+
}
116+
}
98117
}

warehouse/query-core/src/test/java/datawave/query/util/MockMetadataHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public MockMetadataHelper() {
7373
Collections.emptySet());
7474
}
7575

76+
public MockMetadataHelper(Set<Authorizations> allMetadataAuths, Set<Authorizations> auths, Set<Authorizations> fullUserAuths, AccumuloClient client) {
77+
super(createAllFieldMetadataHelperWithCertainAuths(client, allMetadataAuths, auths), allMetadataAuths, client, TableName.METADATA, auths,
78+
fullUserAuths);
79+
}
80+
7681
private static AllFieldMetadataHelper createAllFieldMetadataHelper(AccumuloClient client) {
7782
final Set<Authorizations> allMetadataAuths = Collections.emptySet();
7883
final Set<Authorizations> auths = Collections.emptySet();
@@ -82,6 +87,14 @@ private static AllFieldMetadataHelper createAllFieldMetadataHelper(AccumuloClien
8287

8388
}
8489

90+
private static AllFieldMetadataHelper createAllFieldMetadataHelperWithCertainAuths(AccumuloClient client, Set<Authorizations> allMetadataAuths,
91+
Set<Authorizations> auths) {
92+
TypeMetadataHelper tmh = new TypeMetadataHelper(Maps.newHashMap(), allMetadataAuths, client, TableName.METADATA, auths, false);
93+
CompositeMetadataHelper cmh = new CompositeMetadataHelper(client, TableName.METADATA, auths);
94+
return new AllFieldMetadataHelper(tmh, cmh, client, TableName.METADATA, auths, allMetadataAuths);
95+
96+
}
97+
8598
private static AccumuloClient getClient() {
8699
try {
87100
return new InMemoryAccumuloClient("root", new InMemoryInstance());

0 commit comments

Comments
 (0)