Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed Dec 1, 2023
1 parent 3809a2f commit 38ecfd1
Show file tree
Hide file tree
Showing 15 changed files with 731 additions and 743 deletions.
109 changes: 59 additions & 50 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.qdrant</groupId>
<artifactId>spark</artifactId>
Expand Down Expand Up @@ -115,52 +116,60 @@
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<!-- maven-assembly-plugin -->
<profile>
<id>assembly</id>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.21.1</version>
<goals>
<goal>format</goal>
</goals>
</plugin>
</plugins>
</build>
<profiles>
<!-- maven-assembly-plugin -->
<profile>
<id>assembly</id>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
147 changes: 71 additions & 76 deletions src/main/java/io/qdrant/spark/Qdrant.java
Original file line number Diff line number Diff line change
@@ -1,98 +1,93 @@
package io.qdrant.spark;

import org.apache.spark.sql.sources.DataSourceRegister;
import org.apache.spark.sql.types.StructType;
import org.apache.spark.sql.util.CaseInsensitiveStringMap;
import org.apache.spark.sql.connector.catalog.TableProvider;
import org.apache.spark.sql.connector.catalog.Table;
import org.apache.spark.sql.connector.expressions.Transform;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.spark.sql.connector.catalog.Table;
import org.apache.spark.sql.connector.catalog.TableProvider;
import org.apache.spark.sql.connector.expressions.Transform;
import org.apache.spark.sql.sources.DataSourceRegister;
import org.apache.spark.sql.types.StructType;
import org.apache.spark.sql.util.CaseInsensitiveStringMap;

/**
* A class that implements the TableProvider and DataSourceRegister interfaces.
* Provides methods to infer schema, get table, and check required options.
* A class that implements the TableProvider and DataSourceRegister interfaces. Provides methods to
* infer schema, get table, and check required options.
*/
public class Qdrant implements TableProvider, DataSourceRegister {

private final String[] requiredFields = new String[] {
"schema",
"collection_name",
"embedding_field",
"qdrant_url"
};
private final String[] requiredFields =
new String[] {"schema", "collection_name", "embedding_field", "qdrant_url"};

/**
* Returns the short name of the data source.
*
* @return The short name of the data source.
*/
@Override
public String shortName() {
return "qdrant";
}
/**
* Returns the short name of the data source.
*
* @return The short name of the data source.
*/
@Override
public String shortName() {
return "qdrant";
}

/**
* Infers the schema of the data source based on the provided options.
*
* @param options The options used to infer the schema.
* @return The inferred schema.
*/
@Override
public StructType inferSchema(CaseInsensitiveStringMap options) {
/**
* Infers the schema of the data source based on the provided options.
*
* @param options The options used to infer the schema.
* @return The inferred schema.
*/
@Override
public StructType inferSchema(CaseInsensitiveStringMap options) {

StructType schema = (StructType) StructType.fromJson(options.get("schema"));
checkRequiredOptions(options, schema);
StructType schema = (StructType) StructType.fromJson(options.get("schema"));
checkRequiredOptions(options, schema);

return schema;
};
return schema;
}
;

/**
* Returns a table for the data source based on the provided schema,
* partitioning, and properties.
*
* @param schema The schema of the table.
* @param partitioning The partitioning of the table.
* @param properties The properties of the table.
* @return The table for the data source.
*/
@Override
public Table getTable(StructType schema, Transform[] partitioning, Map<String, String> properties) {
QdrantOptions options = new QdrantOptions(properties);
return new QdrantCluster(options, schema);
}
/**
* Returns a table for the data source based on the provided schema, partitioning, and properties.
*
* @param schema The schema of the table.
* @param partitioning The partitioning of the table.
* @param properties The properties of the table.
* @return The table for the data source.
*/
@Override
public Table getTable(
StructType schema, Transform[] partitioning, Map<String, String> properties) {
QdrantOptions options = new QdrantOptions(properties);
return new QdrantCluster(options, schema);
}

/**
* Checks if the required options are present in the provided options and if the
* id_field and embedding_field
* options are present in the provided schema.
*
* @param options The options to check.
* @param schema The schema to check.
*/
void checkRequiredOptions(CaseInsensitiveStringMap options, StructType schema) {
for (String fieldName : requiredFields) {
if (!options.containsKey(fieldName)) {
throw new IllegalArgumentException(fieldName + " option is required");
}
}
/**
* Checks if the required options are present in the provided options and if the id_field and
* embedding_field options are present in the provided schema.
*
* @param options The options to check.
* @param schema The schema to check.
*/
void checkRequiredOptions(CaseInsensitiveStringMap options, StructType schema) {
for (String fieldName : requiredFields) {
if (!options.containsKey(fieldName)) {
throw new IllegalArgumentException(fieldName + " option is required");
}
}

List<String> fieldNames = Arrays.asList(schema.fieldNames());
List<String> fieldNames = Arrays.asList(schema.fieldNames());

if (options.containsKey("id_field")) {
String idField = options.get("id_field").toString();
if (options.containsKey("id_field")) {
String idField = options.get("id_field").toString();

if (!fieldNames.contains(idField)) {
throw new IllegalArgumentException("id_field option is not present in the schema");
}
}
if (!fieldNames.contains(idField)) {
throw new IllegalArgumentException("id_field option is not present in the schema");
}
}

String embeddingField = options.get("embedding_field").toString();
String embeddingField = options.get("embedding_field").toString();

if (!fieldNames.contains(embeddingField)) {
throw new IllegalArgumentException("embedding_field option is not present in the schema");
}
if (!fieldNames.contains(embeddingField)) {
throw new IllegalArgumentException("embedding_field option is not present in the schema");
}
}
}
}
44 changes: 21 additions & 23 deletions src/main/java/io/qdrant/spark/QdrantBatchWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,33 @@
import org.apache.spark.sql.types.StructType;

/**
* QdrantBatchWriter class implements the BatchWrite interface and provides a
* factory for creating
* QdrantDataWriterFactory instances. It also provides methods for committing or
* aborting write operations.
* QdrantBatchWriter class implements the BatchWrite interface and provides a factory for creating
* QdrantDataWriterFactory instances. It also provides methods for committing or aborting write
* operations.
*/
public class QdrantBatchWriter implements BatchWrite {

private final QdrantOptions options;
private final StructType schema;
private final QdrantOptions options;
private final StructType schema;

public QdrantBatchWriter(QdrantOptions options, StructType schema) {
this.options = options;
this.schema = schema;
}
public QdrantBatchWriter(QdrantOptions options, StructType schema) {
this.options = options;
this.schema = schema;
}

@Override
public DataWriterFactory createBatchWriterFactory(PhysicalWriteInfo info) {
return new QdrantDataWriterFactory(options, schema);
}
@Override
public DataWriterFactory createBatchWriterFactory(PhysicalWriteInfo info) {
return new QdrantDataWriterFactory(options, schema);
}

@Override
public void commit(WriterCommitMessage[] messages) {
// TODO Auto-generated method stub
@Override
public void commit(WriterCommitMessage[] messages) {
// TODO Auto-generated method stub

}

@Override
public void abort(WriterCommitMessage[] messages) {
// TODO Auto-generated method stub
}
}

@Override
public void abort(WriterCommitMessage[] messages) {
// TODO Auto-generated method stub
}
}
Loading

0 comments on commit 38ecfd1

Please sign in to comment.