Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ jobs:
!:trino-mysql,
!:trino-postgresql,
!:trino-sqlserver,
!:trino-mariadb,
!:trino-oracle,
!:trino-kudu,
!:trino-druid,
Expand Down Expand Up @@ -402,6 +403,7 @@ jobs:
- { modules: plugin/trino-postgresql }
- { modules: plugin/trino-sqlserver }
- { modules: plugin/trino-singlestore }
- { modules: plugin/trino-mariadb }
- { modules: plugin/trino-oracle }
- { modules: plugin/trino-kudu }
- { modules: plugin/trino-druid }
Expand Down
6 changes: 6 additions & 0 deletions core/trino-server/src/main/provisio/trino.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
</artifact>
</artifactSet>

<artifactSet to="plugin/mariadb">
<artifact id="${project.groupId}:trino-mariadb:zip:${project.version}">
<unpack />
</artifact>
</artifactSet>

<artifactSet to="plugin/mysql">
<artifact id="${project.groupId}:trino-mysql:zip:${project.version}">
<unpack />
Expand Down
1 change: 1 addition & 0 deletions docs/src/main/sphinx/connector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ from different data sources.
Kinesis <connector/kinesis>
Kudu <connector/kudu>
Local File <connector/localfile>
MariaDB <connector/mariadb>
Memory <connector/memory>
MongoDB <connector/mongodb>
MySQL <connector/mysql>
Expand Down
162 changes: 162 additions & 0 deletions docs/src/main/sphinx/connector/mariadb.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
=================
MariaDB connector
=================

The MariaDB connector allows querying and
creating tables in an external MariaDB database.

Requirements
------------

To connect to MariaDB, you need:

* MariaDB version 10.2 or higher.
* Network access from the Trino coordinator and workers to MariaDB. Port
3306 is the default port.

Configuration
-------------

To configure the MariaDB connector, create a catalog properties file
in ``etc/catalog`` named, for example, ``mariadb.properties``, to
mount the MariaDB connector as the ``mariadb`` catalog.
Create the file with the following contents, replacing the
connection properties as appropriate for your setup:

.. code-block:: text

connector.name=mariadb
connection-url=jdbc:mariadb://example.net:3306
connection-user=root
connection-password=secret

.. include:: jdbc-common-configurations.fragment

.. include:: jdbc-case-insensitive-matching.fragment

.. include:: non-transactional-insert.fragment

Querying MariaDB
----------------

The MariaDB connector provides a schema for every MariaDB *database*.
You can see the available MariaDB databases by running ``SHOW SCHEMAS``::

SHOW SCHEMAS FROM mariadb;

If you have a MariaDB database named ``web``, you can view the tables
in this database by running ``SHOW TABLES``::

SHOW TABLES FROM mariadb.web;

You can see a list of the columns in the ``clicks`` table in the ``web``
database using either of the following::

DESCRIBE mariadb.web.clicks;
SHOW COLUMNS FROM mariadb.web.clicks;

Finally, you can access the ``clicks`` table in the ``web`` database::

SELECT * FROM mariadb.web.clicks;

If you used a different name for your catalog properties file, use
that catalog name instead of ``mariadb`` in the above examples.

.. mariadb-type-mapping:

Type mapping
------------

Trino supports the following MariaDB data types:
Comment thread
hashhar marked this conversation as resolved.
Outdated

================================== ===============================
MariaDB Type Trino Type
================================== ===============================
``boolean`` ``tinyint``
``tinyint`` ``tinyint``
``smallint`` ``smallint``
``int`` ``integer``
``bigint`` ``bigint``
Comment thread
hashhar marked this conversation as resolved.
Outdated
``tinyint unsigned`` ``smallint``
``smallint unsigned`` ``integer``
``mediumint unsigned`` ``integer``
``integer unsigned`` ``bigint``
``bigint unsigned`` ``decimal(20,0)``
``float`` ``real``
``double`` ``double``
Comment thread
hashhar marked this conversation as resolved.
Outdated
``decimal(p,s)`` ``decimal(p,s)``
``char(n)`` ``char(n)``
``tinytext`` ``varchar(255)``
``text`` ``varchar(65535)``
``mediumtext`` ``varchar(16777215)``
``longtext`` ``varchar``
``varchar(n)`` ``varchar(n)``
``tinyblob`` ``varbinary``
``blob`` ``varbinary``
``mediumblob`` ``varbinary``
``longblob`` ``varbinary``
``varbinary(n)`` ``varbinary``
``date`` ``date``
``time(n)`` ``time(n)``
================================== ===============================

Complete list of `MariaDB data types
<https://mariadb.com/kb/en/data-types/>`_.


.. include:: jdbc-type-mapping.fragment

.. _mariadb-sql-support:

SQL support
-----------

The connector provides read access and write access to data and metadata in
a MariaDB database. In addition to the :ref:`globally available
<sql-globally-available>` and :ref:`read operation <sql-read-operations>`
statements, the connector supports the following features:

* :doc:`/sql/insert`
* :doc:`/sql/delete`
* :doc:`/sql/truncate`
* :doc:`/sql/create-table`
* :doc:`/sql/create-table-as`
* :doc:`/sql/drop-table`
* :doc:`/sql/alter-table`
* :doc:`/sql/create-schema`
* :doc:`/sql/drop-schema`

.. include:: sql-delete-limitation.fragment

Performance
-----------

The connector includes a number of performance improvements, detailed in the
following sections.

.. _mariadb-pushdown:

Pushdown
^^^^^^^^

The connector supports pushdown for a number of operations:

* :ref:`join-pushdown`
* :ref:`limit-pushdown`
* :ref:`topn-pushdown`

:ref:`Aggregate pushdown <aggregation-pushdown>` for the following functions:

* :func:`avg`
* :func:`count`
* :func:`max`
* :func:`min`
* :func:`sum`
* :func:`stddev`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we list aliases together with the original function name? Pre-existing, would need change in all connectors.

* :func:`stddev_pop`
* :func:`stddev_samp`
* :func:`variance`
* :func:`var_pop`
* :func:`var_samp`

.. include:: no-pushdown-text-type.fragment
164 changes: 164 additions & 0 deletions plugin/trino-mariadb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?xml version="1.0"?>
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.trino</groupId>
<artifactId>trino-root</artifactId>
<version>379-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>trino-mariadb</artifactId>
<description>Trino - MariaDB Connector</description>
<packaging>trino-plugin</packaging>

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
</properties>

<dependencies>
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-base-jdbc</artifactId>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-plugin-toolkit</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>

<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>

<!-- used by tests but also needed transitively -->
<dependency>
<groupId>io.airlift</groupId>
<artifactId>log</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>log-manager</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Trino SPI -->
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-spi</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>slice</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-core</artifactId>
<scope>provided</scope>
</dependency>

<!-- for testing -->
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-base-jdbc</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-main</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-main</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-testing</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-tpch</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino.tpch</groupId>
<artifactId>tpch</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>testing</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mariadb</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.mariadb;

import io.trino.plugin.jdbc.aggregation.BaseImplementAvgBigint;

public class ImplementAvgBigint
extends BaseImplementAvgBigint
{
@Override
protected String getRewriteFormatExpression()
{
return "avg((%s * 1.0))";
}
}
Loading