Skip to content

Commit

Permalink
Added hashcode for DataSourceMetadata
Browse files Browse the repository at this point in the history
Signed-off-by: Guian Gumpac <[email protected]>
  • Loading branch information
GumpacG committed Aug 22, 2023
1 parent 4c582d0 commit 5f6eaf2
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -67,11 +68,13 @@ public class BuiltinFunctionRepository {
* @return singleton instance
*/
public static synchronized BuiltinFunctionRepository getInstance(DataSourceService dataSourceService) {
// TODO: get hashCode of dataSourceMetadata
int dataSourceServiceHash = dataSourceService.hashCode();
Set<DataSourceMetadata> dataSourceMetadataSet =
dataSourceService.getDataSourceMetadata(true);
Set<Integer> dataSourceServiceHashSet =
dataSourceMetadataSet.stream().map(metadata -> metadata.hashCode()).collect(Collectors.toSet());

// Creates new Repository for every dataSourceService
if (!instance.containsKey(dataSourceServiceHash)) {
if (!dataSourceServiceHashSet.stream().anyMatch(hash -> instance.containsKey(hash))) {
BuiltinFunctionRepository repository = new BuiltinFunctionRepository(new HashMap<>());

// Register all built-in functions
Expand All @@ -90,15 +93,16 @@ public static synchronized BuiltinFunctionRepository getInstance(DataSourceServi
// TODO: remove this resolver when Analyzers are moved to opensearch module
repository.register(new NestedFunctionResolver());

for (DataSourceMetadata metadata : dataSourceService.getDataSourceMetadata(true)) {
for (DataSourceMetadata metadata : dataSourceMetadataSet) {
dataSourceService
.getDataSource(metadata.getName())
.getStorageEngine().getFunctions().
forEach(function -> repository.register(function));
instance.put(metadata.hashCode(), repository);
}
instance.put(dataSourceServiceHash, repository);
return repository;
}
return instance.get(dataSourceServiceHash);
return instance.get(dataSourceServiceHashSet.iterator().next());
}

/**
Expand Down

0 comments on commit 5f6eaf2

Please sign in to comment.