Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused constructor parameters #169

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions src/main/java/pl/net/was/trino/git/BranchesRecordCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
Expand All @@ -46,7 +45,7 @@ public class BranchesRecordCursor

private List<String> fields;

public BranchesRecordCursor(List<GitColumnHandle> columnHandles, Git repo, Optional<List<String>> commitIds)
public BranchesRecordCursor(List<GitColumnHandle> columnHandles, Git repo)
{
this.columnHandles = columnHandles;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pl/net/was/trino/git/GitMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class GitMetadata
implements ConnectorMetadata
{
private final GitClient gitClient;
private String catalogName;
private final String catalogName;

@Inject
public GitMetadata(@CatalogName String catalogName, GitClient gitClient)
Expand Down
36 changes: 11 additions & 25 deletions src/main/java/pl/net/was/trino/git/GitRecordSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.List;
import java.util.Map;
Expand All @@ -43,7 +41,7 @@ public class GitRecordSet
private final List<GitColumnHandle> columnHandles;
private final List<Type> columnTypes;
private final String tableName;
private Git repo;
private final Git repo;
private final Optional<List<String>> commitIds;

public GitRecordSet(GitSplit split, GitTableHandle table, List<GitColumnHandle> columnHandles)
Expand Down Expand Up @@ -78,30 +76,18 @@ public List<Type> getColumnTypes()
@Override
public RecordCursor cursor()
{
Map<String, Class<?>> map = Map.of(
"branches", BranchesRecordCursor.class,
"commits", CommitsRecordCursor.class,
"diff_stats", DiffStatsRecordCursor.class,
"objects", ObjectsRecordCursor.class,
"tags", TagsRecordCursor.class,
"trees", TreesRecordCursor.class);
Class<?> clazz = map.get(tableName);
if (clazz == null) {
Map<String, RecordCursorProvider> map = Map.of(
"branches", (columnHandles, repo, commitIds) -> new BranchesRecordCursor(columnHandles, repo),
"commits", CommitsRecordCursor::new,
"diff_stats", DiffStatsRecordCursor::new,
"objects", (columnHandles, repo, commitIds) -> new ObjectsRecordCursor(columnHandles, repo),
"tags", (columnHandles, repo, commitIds) -> new TagsRecordCursor(columnHandles, repo),
"trees", TreesRecordCursor::new);
RecordCursorProvider recordCursorProvider = map.get(tableName);
if (recordCursorProvider == null) {
return null;
}
Constructor<?> ctr;
try {
ctr = clazz.getConstructor(List.class, Git.class, Optional.class);
}
catch (NoSuchMethodException e) {
throw new RuntimeException("Missing cursor constructor", e);
}
try {
return (RecordCursor) ctr.newInstance(columnHandles, repo, commitIds);
}
catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Unknown exception", e);
}
return recordCursorProvider.create(columnHandles, repo, commitIds);
}

private Git getRepo(URI uri)
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/pl/net/was/trino/git/ObjectsRecordCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

import static com.google.common.base.Preconditions.checkArgument;
Expand All @@ -49,7 +48,7 @@ public class ObjectsRecordCursor

private final Map<Integer, Function<ObjectsRecordCursor, Slice>> strFieldGetters = new HashMap<>();

public ObjectsRecordCursor(List<GitColumnHandle> columnHandles, Git repo, Optional<List<String>> commitIds)
public ObjectsRecordCursor(List<GitColumnHandle> columnHandles, Git repo)
{
this.columnHandles = columnHandles;

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/pl/net/was/trino/git/RecordCursorProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed 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 pl.net.was.trino.git;

import io.trino.spi.connector.RecordCursor;
import org.eclipse.jgit.api.Git;

import java.util.List;
import java.util.Optional;

public interface RecordCursorProvider
{
RecordCursor create(List<GitColumnHandle> columnHandles, Git repo, Optional<List<String>> commitIds);
}
3 changes: 1 addition & 2 deletions src/main/java/pl/net/was/trino/git/TagsRecordCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.util.Iterator;
import java.util.List;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
Expand All @@ -38,7 +37,7 @@ public class TagsRecordCursor

private List<String> fields;

public TagsRecordCursor(List<GitColumnHandle> columnHandles, Git repo, Optional<List<String>> commitIds)
public TagsRecordCursor(List<GitColumnHandle> columnHandles, Git repo)
{
this.columnHandles = columnHandles;

Expand Down
10 changes: 3 additions & 7 deletions src/test/java/pl/net/was/trino/git/TestGitClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TimeZone;

import static com.google.common.io.MoreFiles.deleteRecursively;
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
import static org.assertj.core.api.Assertions.assertThat;

public class TestGitClient
Expand All @@ -54,10 +53,7 @@
return;
}
if (localPath.exists()) {
Files.walk(localPath.toPath())
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
deleteRecursively(localPath.toPath(), ALLOW_INSECURE);
}

Repository repository = FileRepositoryBuilder.create(new File(localPath, ".git"));
Expand All @@ -69,7 +65,7 @@
throw new IOException("Could not create file " + myFile);
}

PersonIdent author = new PersonIdent("test", "[email protected]", new Date(1580897313000L), TimeZone.getTimeZone("UTC"));

Check warning on line 68 in src/test/java/pl/net/was/trino/git/TestGitClient.java

View workflow job for this annotation

GitHub Actions / build

Date has a bad API that leads to bugs; prefer java.time.Instant or LocalDate.
// commit the new file
Git git = new Git(repository);
git.add().addFilepattern(".").call();
Expand All @@ -79,7 +75,7 @@
.setCommitter(author)
.call();

try (PrintWriter writer = new PrintWriter(myFile)) {

Check warning on line 78 in src/test/java/pl/net/was/trino/git/TestGitClient.java

View workflow job for this annotation

GitHub Actions / build

Implicit use of the platform default charset, which can result in differing behaviour between JVM executions or incorrect behavior if the encoding of the data source doesn't match expectations.
writer.append("Hello, world!");
}
if (!myFile.setLastModified(1580897600000L)) {
Expand Down
Loading