diff --git a/mondrian/src/it/java/mondrian/spi/impl/MariaDBDialectTest.java b/mondrian/src/it/java/mondrian/spi/impl/MariaDBDialectTest.java new file mode 100644 index 0000000000..9f06a50bc5 --- /dev/null +++ b/mondrian/src/it/java/mondrian/spi/impl/MariaDBDialectTest.java @@ -0,0 +1,61 @@ +/* + // This software is subject to the terms of the Eclipse Public License v1.0 + // Agreement, available at the following URL: + // http://www.eclipse.org/legal/epl-v10.html. + // You must accept the terms of that agreement to use this software. + // + // Copyright (C) 2018 - 2021 Hitachi Vantara + // All Rights Reserved. + */ +package mondrian.spi.impl; + +import junit.framework.TestCase; +import mondrian.spi.Dialect; +import mondrian.spi.DialectManager; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.Statement; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author Petr Procházka (petrprochy) + * @since 2021/08/10 + */ +public class MariaDBDialectTest extends TestCase { + private final String version = "10.2.17-MariaDB-log"; + + private final Connection connection = mock(Connection.class); + private final Statement statement = mock(Statement.class); + private MariaDBDialect dialect; + + @Override + public void setUp() throws Exception { + DatabaseMetaData metaData = mock( DatabaseMetaData.class ); + when( connection.getMetaData() ).thenReturn( metaData ); + when( metaData.getDatabaseProductName() ).thenReturn( "MariaDB" ); + when( metaData.getDatabaseProductVersion() ).thenReturn( version ); + when( connection.createStatement() ).thenReturn( statement ); + dialect = new MariaDBDialect( connection ); + } + + @SuppressWarnings("SqlNoDataSourceInspection") + public void testCreateDialect() throws Exception { + final DataSource dataSource = mock( DataSource.class ); + final ResultSet resultSet = mock( ResultSet.class ); + when( resultSet.next() ).thenReturn( true ); + when( resultSet.getString( 1 ) ).thenReturn( version ); + when( statement.executeQuery( "select version()" ) ).thenReturn( resultSet ); + + final Dialect dialect = DialectManager.createDialect( dataSource, connection ); + assertEquals( "Implementation class", dialect.getClass(), MariaDBDialect.class ); + } + + public void testAllowFromQuery() { + assertTrue("Allow from query", dialect.allowsFromQuery()); + } +} diff --git a/mondrian/src/it/java/mondrian/test/Main.java b/mondrian/src/it/java/mondrian/test/Main.java index c9f67b6b82..0bba6c2870 100644 --- a/mondrian/src/it/java/mondrian/test/Main.java +++ b/mondrian/src/it/java/mondrian/test/Main.java @@ -126,13 +126,7 @@ import mondrian.rolap.sql.SqlQueryTest; import mondrian.server.FileRepositoryTest; import mondrian.spi.DialectUtilTest; -import mondrian.spi.impl.ImpalaDialectTest; -import mondrian.spi.impl.JdbcDialectImplTest; -import mondrian.spi.impl.MonetDbDialectTest; -import mondrian.spi.impl.MySqlDialectTest; -import mondrian.spi.impl.OracleDialectTest; -import mondrian.spi.impl.PostgreSqlDialectTest; -import mondrian.spi.impl.SybaseDialectTest; +import mondrian.spi.impl.*; import mondrian.test.build.CodeComplianceTest; import mondrian.test.clearview.BatchedFillTest; import mondrian.test.clearview.CVBasicTest; @@ -443,6 +437,7 @@ public static Test suite() throws Exception { addTest( suite, PostgreSqlDialectTest.class ); addTest( suite, OracleDialectTest.class ); addTest( suite, MySqlDialectTest.class ); + addTest( suite, MariaDBDialectTest.class ); addTest( suite, MonetDbDialectTest.class ); addTest( suite, DialectUtilTest.class ); addTest( suite, IdBatchResolverTest.class ); diff --git a/mondrian/src/main/java/mondrian/spi/impl/MariaDBDialect.java b/mondrian/src/main/java/mondrian/spi/impl/MariaDBDialect.java index cda6063b33..5e59e2ab8b 100644 --- a/mondrian/src/main/java/mondrian/spi/impl/MariaDBDialect.java +++ b/mondrian/src/main/java/mondrian/spi/impl/MariaDBDialect.java @@ -1,48 +1,54 @@ -/* -// This software is subject to the terms of the Eclipse Public License v1.0 -// Agreement, available at the following URL: -// http://www.eclipse.org/legal/epl-v10.html. -// You must accept the terms of that agreement to use this software. -// -// Copyright (C) 2016 - 2017 Hitachi Vantara -// All Rights Reserved. -*/ - -package mondrian.spi.impl; - -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.SQLException; - -import mondrian.olap.Util; -import mondrian.spi.Dialect.DatabaseProduct; - -public class MariaDBDialect extends MySqlDialect { - - public static final JdbcDialectFactory FACTORY = - new JdbcDialectFactory( - MariaDBDialect.class, - DatabaseProduct.MARIADB) - { - @Override - protected boolean acceptsConnection(Connection connection) { - return super.acceptsConnection(connection); - } - }; - - - public MariaDBDialect( Connection connection ) throws SQLException { - super( connection ); - } - - @Override - protected String deduceProductName(DatabaseMetaData databaseMetaData) { - // It is possible for someone to use the MariaDB JDBC driver with Infobright . . . - final String productName = super.deduceProductName(databaseMetaData); - if (isInfobright(databaseMetaData)) { - return "MySQL (Infobright)"; - } - return productName; - } - -} +/* +// This software is subject to the terms of the Eclipse Public License v1.0 +// Agreement, available at the following URL: +// http://www.eclipse.org/legal/epl-v10.html. +// You must accept the terms of that agreement to use this software. +// +// Copyright (C) 2016 - 2021 Hitachi Vantara +// All Rights Reserved. +*/ + +package mondrian.spi.impl; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; + +public class MariaDBDialect extends MySqlDialect { + + public static final JdbcDialectFactory FACTORY = + new JdbcDialectFactory( + MariaDBDialect.class, + DatabaseProduct.MARIADB) + { + @Override + protected boolean acceptsConnection(Connection connection) { + return super.acceptsConnection(connection); + } + }; + + + public MariaDBDialect( Connection connection ) throws SQLException { + super( connection ); + } + + @Override + protected String deduceProductName(DatabaseMetaData databaseMetaData) { + // It is possible for someone to use the MariaDB JDBC driver with Infobright . . . + final String productName = super.deduceProductName(databaseMetaData); + if (isInfobright(databaseMetaData)) { + return "MySQL (Infobright)"; + } + return productName; + } + + /** + * For MariaDB always allows subquery in the from query clause. Problem is with any store engines, ex. Columnstore. + * + * @return Always true. + */ + @Override + public boolean allowsFromQuery() { + return true; + } +}