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

MariaDB dialect detection #1090

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
61 changes: 61 additions & 0 deletions mondrian/src/it/java/mondrian/spi/impl/MariaDBDialectTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
9 changes: 2 additions & 7 deletions mondrian/src/it/java/mondrian/test/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
102 changes: 54 additions & 48 deletions mondrian/src/main/java/mondrian/spi/impl/MariaDBDialect.java
Original file line number Diff line number Diff line change
@@ -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 <tt>true</tt>.
*/
@Override
public boolean allowsFromQuery() {
return true;
}
}