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

Added testConnection feature in CSV adapter. Issue #450 #470

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions core/src/main/java/org/polypheny/db/adapter/DataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,7 @@ private AdapterType getAdapterType() {
return AdapterType.SOURCE;
}


public void testConnection(){}

}
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,35 @@ private void addInformationExportedColumns() {
}
}


public void testConnection(){
File directory = new File(csvDir.getPath());

// Check if the directory exists
if (!directory.exists() ) {
throw new Error("The specified path is not a valid directory.");
}

// List all files in the directory
File[] files = directory.listFiles();
if(files == null)
throw new Error("THERE IS NO CSV FILE TO UPLOAD. ");

int badFiles = 0;
if (files != null) {
// Check each file if it has a .csv extension
for (File file : files) {
System.out.println(file.getName());
if (!file.isFile() || !file.getName().toLowerCase().endsWith(".csv"))
badFiles++;

}
}

if(badFiles==files.length)
throw new Error("NO VALID CSV FILE FOUND. ");


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,30 @@ private void addInformationExportedColumns() {
}
}


@Override
public void testConnection() {

File directory = new File(excelDir.getPath());
// Check if the directory exists
if (!directory.exists() ) {
shutdown();
throw new Error("The specified path is not a valid directory.");
}
File[] files = directory.listFiles();

int goodFile=0;
for(File file : files){
String fileName = file.getName();
if(fileName.endsWith( ".xlsx" ) || fileName.endsWith( ".xlsx.gz" ) || fileName.endsWith( ".xls" ) || fileName.endsWith( ".xls.gz" ))
goodFile++;
}
if(goodFile==0){
throw new RuntimeException("No Excel sheet found.");
}


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
import java.util.StringJoiner;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.calcite.linq4j.AbstractEnumerable;
import org.apache.calcite.linq4j.Enumerator;
import org.polypheny.db.adapter.Adapter.AdapterProperties;
import org.polypheny.db.adapter.Adapter.AdapterSettingString;
import org.polypheny.db.adapter.AdapterManager;
import org.polypheny.db.adapter.DataSource;
import org.polypheny.db.adapter.DeployMode;
import org.polypheny.db.catalog.entity.CatalogColumnPlacement;
Expand Down Expand Up @@ -302,4 +305,13 @@ protected void registerInformationPage( String uniqueName ) {
}
}


@Override
public void testConnection(){

if(currentSchema.getConvention().getFileSchema().getRootDir()==null)
throw new RuntimeException("The specified QFS root dir does not exist!");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.polypheny.db.adapter.Adapter.AdapterSettingString;
import org.polypheny.db.adapter.DeployMode;
import org.polypheny.db.adapter.jdbc.connection.ConnectionFactory;
import org.polypheny.db.adapter.jdbc.connection.ConnectionHandler;
import org.polypheny.db.adapter.jdbc.connection.TransactionalConnectionFactory;
import org.polypheny.db.adapter.jdbc.sources.AbstractJdbcSource;
import org.polypheny.db.catalog.Adapter;
Expand All @@ -38,6 +39,9 @@
import org.polypheny.db.schema.Table;
import org.polypheny.db.sql.language.SqlDialect;
import org.polypheny.db.sql.language.dialect.MonetdbSqlDialect;
import org.polypheny.db.transaction.PUID;
import org.polypheny.db.transaction.PUID.Type;
import org.polypheny.db.transaction.PolyXid;


@Slf4j
Expand Down Expand Up @@ -133,4 +137,22 @@ protected boolean requiresSchema() {
return true;
}


@Override
public void testConnection(){

PolyXid randomXid = PolyXid.generateLocalTransactionIdentifier( PUID.randomPUID( Type.NODE ), PUID.randomPUID( Type.TRANSACTION ) );
ConnectionHandler connectionHandler = connectionFactory.getConnectionHandler(randomXid);

// Execute an Postgres query
String sql = "SELECT 1";

try {
connectionHandler.executeQuery( sql );
} catch ( SQLException e ) {
throw new RuntimeException( e );
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.polypheny.db.adapter.Adapter.AdapterSettingList;
import org.polypheny.db.adapter.Adapter.AdapterSettingString;
import org.polypheny.db.adapter.DeployMode;
import org.polypheny.db.adapter.jdbc.connection.ConnectionHandler;
import org.polypheny.db.adapter.jdbc.sources.AbstractJdbcSource;
import org.polypheny.db.catalog.Adapter;
import org.polypheny.db.catalog.entity.CatalogColumnPlacement;
Expand All @@ -37,6 +38,9 @@
import org.polypheny.db.schema.Schema;
import org.polypheny.db.schema.Table;
import org.polypheny.db.sql.language.dialect.MysqlSqlDialect;
import org.polypheny.db.transaction.PUID;
import org.polypheny.db.transaction.PUID.Type;
import org.polypheny.db.transaction.PolyXid;

public class MysqlSourcePlugin extends Plugin {

Expand Down Expand Up @@ -135,6 +139,22 @@ protected boolean requiresSchema() {
return false;
}


@Override
public void testConnection(){

PolyXid randomXid = PolyXid.generateLocalTransactionIdentifier( PUID.randomPUID( Type.NODE ), PUID.randomPUID( Type.TRANSACTION ) );
ConnectionHandler connectionHandler = connectionFactory.getConnectionHandler(randomXid);

// Execute an Postgres query
String sql = "SELECT 1";

try {
connectionHandler.executeQuery( sql );
} catch ( SQLException e ) {
throw new RuntimeException( e );
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.polypheny.db.adapter.Adapter.AdapterSettingList;
import org.polypheny.db.adapter.Adapter.AdapterSettingString;
import org.polypheny.db.adapter.DeployMode;
import org.polypheny.db.adapter.jdbc.connection.ConnectionHandler;
import org.polypheny.db.adapter.jdbc.sources.AbstractJdbcSource;
import org.polypheny.db.catalog.Adapter;
import org.polypheny.db.catalog.entity.CatalogColumnPlacement;
Expand All @@ -35,6 +36,9 @@
import org.polypheny.db.schema.Schema;
import org.polypheny.db.schema.Table;
import org.polypheny.db.sql.language.dialect.PostgresqlSqlDialect;
import org.polypheny.db.transaction.PUID;
import org.polypheny.db.transaction.PUID.Type;
import org.polypheny.db.transaction.PolyXid;


@Slf4j
Expand Down Expand Up @@ -124,4 +128,20 @@ protected boolean requiresSchema() {
return true;
}

@Override
public void testConnection(){

PolyXid randomXid = PolyXid.generateLocalTransactionIdentifier( PUID.randomPUID( Type.NODE ), PUID.randomPUID( Type.TRANSACTION ) );
ConnectionHandler connectionHandler = connectionFactory.getConnectionHandler(randomXid);

// Execute an Postgres query
String sql = "SELECT 1";

try {
connectionHandler.executeQuery( sql );
} catch ( SQLException e ) {
throw new RuntimeException( e );
}
}

}