Search in sources :

Example 1 with MetadataStorageTest

use of io.cdap.cdap.spi.metadata.MetadataStorageTest in project cdap by caskdata.

the class DatasetMetadataStorageTest method testSearchWeight.

// this tests is not in MetadataStorageTest,
// because it tests result scoring and sorting specific to the dataset-based implementation
@Test
public void testSearchWeight() throws IOException {
    MetadataStorage mds = getMetadataStorage();
    String ns = "ns1";
    NamespaceId nsId = new NamespaceId(ns);
    MetadataEntity service1 = nsId.app("app1").service("service1").toMetadataEntity();
    MetadataEntity dataset1 = nsId.dataset("ds1").toMetadataEntity();
    MetadataEntity dataset2 = nsId.dataset("ds2").toMetadataEntity();
    // Add metadata
    String multiWordValue = "aV1 av2 ,  -  ,  av3 - av4_av5 av6";
    Map<String, String> userProps = ImmutableMap.of("key1", "value1", "key2", "value2", "multiword", multiWordValue);
    Map<String, String> systemProps = ImmutableMap.of("sysKey1", "sysValue1");
    Set<String> userTags = ImmutableSet.of("tag1", "tag2");
    Set<String> temporaryUserTags = ImmutableSet.of("tag3", "tag4");
    Map<String, String> dataset1UserProps = ImmutableMap.of("sKey1", "sValuee1 sValuee2");
    Map<String, String> dataset2UserProps = ImmutableMap.of("sKey1", "sValue1 sValue2", "Key1", "Value1");
    Set<String> sysTags = ImmutableSet.of("sysTag1");
    MetadataRecord service1Record = new MetadataRecord(service1, union(new Metadata(USER, userTags, userProps), new Metadata(SYSTEM, sysTags, systemProps)));
    mds.apply(new Update(service1Record.getEntity(), service1Record.getMetadata()), MutationOptions.DEFAULT);
    // dd and then remove some metadata for dataset2
    mds.apply(new Update(dataset2, new Metadata(USER, temporaryUserTags, userProps)), MutationOptions.DEFAULT);
    mds.apply(new Remove(dataset2, temporaryUserTags.stream().map(tag -> new ScopedNameOfKind(TAG, USER, tag)).collect(Collectors.toSet())), MutationOptions.DEFAULT);
    mds.apply(new Remove(dataset2, userProps.keySet().stream().map(tag -> new ScopedNameOfKind(PROPERTY, USER, tag)).collect(Collectors.toSet())), MutationOptions.DEFAULT);
    MetadataRecord dataset1Record = new MetadataRecord(dataset1, new Metadata(USER, tags(), dataset1UserProps));
    MetadataRecord dataset2Record = new MetadataRecord(dataset2, new Metadata(USER, tags(), dataset2UserProps));
    mds.batch(ImmutableList.of(new Update(dataset1Record.getEntity(), dataset1Record.getMetadata()), new Update(dataset2Record.getEntity(), dataset2Record.getMetadata())), MutationOptions.DEFAULT);
    // Test score and metadata match
    assertInOrder(mds, SearchRequest.of("value1 multiword:av2").addNamespace(ns).build(), service1Record, dataset2Record);
    assertInOrder(mds, SearchRequest.of("value1 sValue*").addNamespace(ns).setLimit(Integer.MAX_VALUE).build(), dataset2Record, dataset1Record, service1Record);
    assertResults(mds, SearchRequest.of("*").addNamespace(ns).setLimit(Integer.MAX_VALUE).build(), dataset2Record, dataset1Record, service1Record);
    // clean up
    mds.batch(ImmutableList.of(new Drop(service1), new Drop(dataset1), new Drop(dataset2)), MutationOptions.DEFAULT);
}
Also used : Module(com.google.inject.Module) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) ImmutablePair(io.cdap.cdap.common.utils.ImmutablePair) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) SystemDatasetRuntimeModule(io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule) Metadata(io.cdap.cdap.spi.metadata.Metadata) Map(java.util.Map) Closeables(com.google.common.io.Closeables) SearchRequest(io.cdap.cdap.spi.metadata.SearchRequest) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) EnumSet(java.util.EnumSet) PROPERTY(io.cdap.cdap.spi.metadata.MetadataKind.PROPERTY) AfterClass(org.junit.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) SYSTEM(io.cdap.cdap.api.metadata.MetadataScope.SYSTEM) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) BeforeClass(org.junit.BeforeClass) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) AuthorizationTestModule(io.cdap.cdap.security.authorization.AuthorizationTestModule) USER(io.cdap.cdap.api.metadata.MetadataScope.USER) NamespaceAdminTestModule(io.cdap.cdap.common.guice.NamespaceAdminTestModule) MetadataStorage(io.cdap.cdap.spi.metadata.MetadataStorage) TAG(io.cdap.cdap.spi.metadata.MetadataKind.TAG) AuthorizationEnforcementModule(io.cdap.cdap.security.authorization.AuthorizationEnforcementModule) ImmutableList(com.google.common.collect.ImmutableList) ScopedNameOfKind(io.cdap.cdap.spi.metadata.ScopedNameOfKind) TransactionInMemoryModule(org.apache.tephra.runtime.TransactionInMemoryModule) MetadataStorageTest(io.cdap.cdap.spi.metadata.MetadataStorageTest) StorageModule(io.cdap.cdap.data.runtime.StorageModule) TransactionManager(org.apache.tephra.TransactionManager) Iterator(java.util.Iterator) Cursor(io.cdap.cdap.common.metadata.Cursor) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) SearchResponse(io.cdap.cdap.spi.metadata.SearchResponse) Test(org.junit.Test) IOException(java.io.IOException) Scopes(com.google.inject.Scopes) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) Injector(com.google.inject.Injector) EntityScope(io.cdap.cdap.proto.EntityScope) Guice(com.google.inject.Guice) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MetadataRecord(io.cdap.cdap.spi.metadata.MetadataRecord) MutationOptions(io.cdap.cdap.spi.metadata.MutationOptions) Assert(org.junit.Assert) Remove(io.cdap.cdap.spi.metadata.MetadataMutation.Remove) Collections(java.util.Collections) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) AbstractModule(com.google.inject.AbstractModule) MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) ScopedNameOfKind(io.cdap.cdap.spi.metadata.ScopedNameOfKind) Metadata(io.cdap.cdap.spi.metadata.Metadata) Remove(io.cdap.cdap.spi.metadata.MetadataMutation.Remove) Update(io.cdap.cdap.spi.metadata.MetadataMutation.Update) Drop(io.cdap.cdap.spi.metadata.MetadataMutation.Drop) MetadataStorage(io.cdap.cdap.spi.metadata.MetadataStorage) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) MetadataRecord(io.cdap.cdap.spi.metadata.MetadataRecord) MetadataStorageTest(io.cdap.cdap.spi.metadata.MetadataStorageTest) Test(org.junit.Test)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Closeables (com.google.common.io.Closeables)1 AbstractModule (com.google.inject.AbstractModule)1 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 Scopes (com.google.inject.Scopes)1 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)1 SYSTEM (io.cdap.cdap.api.metadata.MetadataScope.SYSTEM)1 USER (io.cdap.cdap.api.metadata.MetadataScope.USER)1 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)1 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)1 LocalLocationModule (io.cdap.cdap.common.guice.LocalLocationModule)1 NamespaceAdminTestModule (io.cdap.cdap.common.guice.NamespaceAdminTestModule)1 Cursor (io.cdap.cdap.common.metadata.Cursor)1 NoOpMetricsCollectionService (io.cdap.cdap.common.metrics.NoOpMetricsCollectionService)1 ImmutablePair (io.cdap.cdap.common.utils.ImmutablePair)1