From ffad8f2ddb26dee4e7b3422f153d80b5340a1a6e Mon Sep 17 00:00:00 2001 From: Ahmed-Elgamel Date: Sun, 3 Mar 2024 22:03:17 +0200 Subject: [PATCH 1/8] Add testConnection method in DataSource all the classes tha extend this DataSource class will provide their implementation --- core/src/main/java/org/polypheny/db/adapter/DataSource.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/org/polypheny/db/adapter/DataSource.java b/core/src/main/java/org/polypheny/db/adapter/DataSource.java index 96aea10ac9..dc226f51f9 100644 --- a/core/src/main/java/org/polypheny/db/adapter/DataSource.java +++ b/core/src/main/java/org/polypheny/db/adapter/DataSource.java @@ -116,4 +116,7 @@ private AdapterType getAdapterType() { return AdapterType.SOURCE; } + + public void testConnection(){} + } From 49263526a949ee669aeb025b3500d0e4c74766fb Mon Sep 17 00:00:00 2001 From: Ahmed-Elgamel Date: Sun, 3 Mar 2024 22:10:47 +0200 Subject: [PATCH 2/8] Implement testConnection method in CSV Adapter There was no validation whether the csv file is valid or not,I tried and I could add any file as a CSV adapter.The method was tested by calling the testConnection() in the CsvSource constructor and it indeed does not allow invlaid CSV file upload. --- .../polypheny/db/adapter/csv/CsvSource.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSource.java b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSource.java index fc9f821aae..a936de5de3 100644 --- a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSource.java +++ b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvSource.java @@ -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. "); + + + } + } From cf9e96edea1a7478e062145f220e9281df2036fb Mon Sep 17 00:00:00 2001 From: Ahmed-Elgamel Date: Tue, 12 Mar 2024 17:36:52 +0200 Subject: [PATCH 3/8] Add testConnection method for PostgresqlSource --- .../postgres/source/PostgresqlSource.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java b/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java index f18597a0b7..be66f5893c 100644 --- a/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java +++ b/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java @@ -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; @@ -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 @@ -124,4 +128,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 ); + } + } + } From 498559058c54eb7c93cf198e0d0e7fdb51cd3cb2 Mon Sep 17 00:00:00 2001 From: Ahmed-Elgamel Date: Tue, 12 Mar 2024 18:01:35 +0200 Subject: [PATCH 4/8] Add testConnection method for MysqlSource --- .../db/adapter/jdbc/MysqlSourcePlugin.java | 22 ++++++++++++++++++- .../postgres/source/PostgresqlSource.java | 2 -- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/mysql-adapter/src/main/java/org/polypheny/db/adapter/jdbc/MysqlSourcePlugin.java b/plugins/mysql-adapter/src/main/java/org/polypheny/db/adapter/jdbc/MysqlSourcePlugin.java index e817d6f23c..17c1622d23 100644 --- a/plugins/mysql-adapter/src/main/java/org/polypheny/db/adapter/jdbc/MysqlSourcePlugin.java +++ b/plugins/mysql-adapter/src/main/java/org/polypheny/db/adapter/jdbc/MysqlSourcePlugin.java @@ -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; @@ -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 { @@ -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 ); + } + } } -} \ No newline at end of file +} diff --git a/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java b/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java index be66f5893c..25af357db5 100644 --- a/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java +++ b/plugins/postgres-adapter/src/main/java/org/polypheny/db/adapter/postgres/source/PostgresqlSource.java @@ -131,8 +131,6 @@ protected boolean requiresSchema() { @Override public void testConnection(){ - - PolyXid randomXid = PolyXid.generateLocalTransactionIdentifier( PUID.randomPUID( Type.NODE ), PUID.randomPUID( Type.TRANSACTION ) ); ConnectionHandler connectionHandler = connectionFactory.getConnectionHandler(randomXid); From 077d11edc554f025cf17565fe7c28c99c713125b Mon Sep 17 00:00:00 2001 From: Ahmed-Elgamel Date: Tue, 12 Mar 2024 18:03:55 +0200 Subject: [PATCH 5/8] Add testConnection method for MonetdbSource --- .../monetdb/sources/MonetdbSource.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java b/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java index d29bbb3589..3e309f2047 100644 --- a/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java +++ b/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java @@ -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; @@ -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 @@ -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 ); + } + } +} + } From fe9c6bd93ad6c41aff611e703d5c8b4e2e9fdd0e Mon Sep 17 00:00:00 2001 From: Ahmed-Elgamel Date: Tue, 12 Mar 2024 21:58:40 +0200 Subject: [PATCH 6/8] removed bracket --- .../org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java b/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java index 3e309f2047..93abde72da 100644 --- a/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java +++ b/plugins/monetdb-adapter/src/main/java/org/polypheny/db/adapter/monetdb/sources/MonetdbSource.java @@ -155,4 +155,4 @@ public void testConnection(){ } } -} + From 2e93355e9372730bf16a33ebc4d2874f9f48934d Mon Sep 17 00:00:00 2001 From: Ahmed-Elgamel Date: Tue, 12 Mar 2024 22:37:47 +0200 Subject: [PATCH 7/8] ADD testConnection method in Qfs DataSource --- .../org/polypheny/db/adapter/file/source/Qfs.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/Qfs.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/Qfs.java index 0f0f449820..df66d9d31c 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/Qfs.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/Qfs.java @@ -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; @@ -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!"); + + } + } From f9fd6e4fed17b3001676ae75bb7228529c36c3a2 Mon Sep 17 00:00:00 2001 From: Ahmed-Elgamel Date: Tue, 12 Mar 2024 23:48:34 +0200 Subject: [PATCH 8/8] ADD testConnection method in Excel DataSource Previously you can add any file with any extension but now testConnection method checks if the file extension is valid --- .../db/adapter/excel/ExcelSource.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelSource.java b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelSource.java index 660bc62455..2e63975943 100644 --- a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelSource.java +++ b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelSource.java @@ -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."); + } + + + } + + }