JDBC

    Once connected, Doris will ingest metadata of databases and tables from the external data sources in order to enable quick access to external data.

    1. Supported datas sources include MySQL, PostgreSQL, Oracle, SQLServer, Clickhouse and Doris.

    Create Catalog

    SinceVersion 1.2.0

    1. MySQL

    SinceVersion 1.2.2

    1. PostgreSQL
    1. "type"="jdbc",
    2. "user"="root",
    3. "password"="123456",
    4. "jdbc_url" = "jdbc:postgresql://127.0.0.1:5449/demo",
    5. "driver_url" = "postgresql-42.5.1.jar",
    6. "driver_class" = "org.postgresql.Driver"
    7. );

    As for data mapping from PostgreSQL to Doris, one Database in Doris corresponds to one schema in the specified database in PostgreSQL (for example, “demo” in jdbc_url above), and one Table in that Database corresponds to one table in that schema. To make it more intuitive, the mapping relations are as follows:

    SinceVersion 1.2.2

    1. Oracle
    1. CREATE CATALOG jdbc_oracle PROPERTIES (
    2. "type"="jdbc",
    3. "user"="root",
    4. "jdbc_url" = "jdbc:oracle:thin:@127.0.0.1:1521:helowin",
    5. "driver_url" = "ojdbc6.jar",
    6. "driver_class" = "oracle.jdbc.driver.OracleDriver"
    7. );

    As for data mapping from Oracle to Doris, one Database in Doris corresponds to one User (for example, “helowin” in jdbc_url above), and one Table in that Database corresponds to one table that the User has access to. In conclusion, the mapping relations are as follows:

    DorisPostgreSQL
    CatalogDatabase
    DatabaseUser
    TableTable

    SinceVersion 1.2.2

    1. Clickhouse
    1. CREATE CATALOG jdbc_clickhouse PROPERTIES (
    2. "type"="jdbc",
    3. "user"="root",
    4. "password"="123456",
    5. "jdbc_url" = "jdbc:clickhouse://127.0.0.1:8123/demo",
    6. "driver_url" = "clickhouse-jdbc-0.3.2-patch11-all.jar",
    7. "driver_class" = "com.clickhouse.jdbc.ClickHouseDriver"
    8. );

    SinceVersion 1.2.2

    1. SQLServer

    As for data mapping from SQLServer to Doris, one Database in Doris corresponds to one schema in the specified database in SQLServer (for example, “doris_test” in jdbc_url above), and one Table in that Database corresponds to one table in that schema. The mapping relations are as follows:

    DorisSQLServer
    CatalogDatabase
    DatabaseSchema
    TableTable

    SinceVersion dev6. Doris

    Jdbc Catalog also support to connect another Doris database:

    1. CREATE CATALOG doris_catalog PROPERTIES (
    2. "type"="jdbc",
    3. "user"="root",
    4. "password"="123456",
    5. "jdbc_url" = "jdbc:mysql://127.0.0.1:9030?useSSL=false",
    6. "driver_url" = "mysql-connector-java-5.1.47.jar",
    7. "driver_class" = "com.mysql.jdbc.Driver"
    8. );

    Currently, Jdbc Catalog only support to use 5.x version of JDBC jar package to connect another Doris database. If you use 8.x version of JDBC jar package, the data type of column may not be matched.

    1. select * from mysql_table where k1 > 1000 and k3 ='term';

    In some cases, the keywords in the database might be used as the field names. For queries to function normally in these cases, Doris will add escape characters to the field names and tables names in SQL statements based on the rules of different databases, such as (``) for MySQL, ([]) for SQLServer, and (“”) for PostgreSQL and Oracle. This might require extra attention on case sensitivity. You can view the query statements sent to these various databases via explain sql.

    Write Data

    SinceVersion 1.2.2After creating a JDBC Catalog in Doris, you can write data or query results to it using the `insert into` statement. You can also ingest data from one JDBC Catalog Table to another JDBC Catalog Table.

    Example:

    1. insert into mysql_table values(1, "doris");
    2. insert into mysql_table select * from table;

    Transaction

    In Doris, data is written to External Tables in batches. If the ingestion process is interrupted, rollbacks might be required. That’s why JDBC Catalog Tables support data writing transactions. You can utilize this feature by setting the session variable: enable_odbc_transcation .

    The transaction mechanism ensures the atomicity of data writing to JDBC External Tables, but it reduces performance to a certain extent. You may decide whether to enable transactions based on your own tradeoff.

    MYSQL TypeDoris TypeComment
    BOOLEANBOOLEAN
    TINYINTTINYINT
    SMALLINTSMALLINT
    MEDIUMINTINT
    INTINT
    BIGINTBIGINT
    UNSIGNED TINYINTSMALLINTDoris does not support UNSIGNED data types so UNSIGNED TINYINT will be mapped to SMALLINT.
    UNSIGNED MEDIUMINTINTDoris does not support UNSIGNED data types so UNSIGNED MEDIUMINT will be mapped to INT.
    UNSIGNED INTBIGINTDoris does not support UNSIGNED data types so UNSIGNED INT will be mapped to BIGINT.
    UNSIGNED BIGINTLARGEINT
    FLOATFLOAT
    DOUBLEDOUBLE
    DECIMALDECIMAL
    DATEDATE
    TIMESTAMPDATETIME
    DATETIMEDATETIME
    YEARSMALLINT
    TIMESTRING
    CHARCHAR
    VARCHARVARCHAR
    TINYTEXT、TEXT、MEDIUMTEXT、LONGTEXT、TINYBLOB、BLOB、MEDIUMBLOB、LONGBLOB、TINYSTRING、STRING、MEDIUMSTRING、LONGSTRING、BINARY、VARBINARY、JSON、SET、BITSTRING
    OtherUNSUPPORTED

    PostgreSQL

    POSTGRESQL TypeDoris TypeComment
    booleanBOOLEAN
    smallint/int2SMALLINT
    integer/int4INT
    bigint/int8BIGINT
    decimal/numericDECIMAL
    real/float4FLOAT
    double precisionDOUBLE
    smallserialSMALLINT
    serialINT
    bigserialBIGINT
    charCHAR
    varchar/textSTRING
    timestampDATETIME
    dateDATE
    timeSTRING
    intervalSTRING
    point/line/lseg/box/path/polygon/circleSTRING
    cidr/inet/macaddrSTRING
    bit/bit(n)/bit varying(n)STRINGbit will be mapped to STRING in Doris. It will be read as true/false instead of 1/0
    uuid/josnbSTRING
    OtherUNSUPPORTED

    SQLServer

    SQLServer TypeDoris TypeComment
    bitBOOLEAN
    tinyintSMALLINTThe tinyint type in SQLServer is an unsigned number so it will be mapped to SMALLINT in Doris.
    smallintSMALLINT
    intINT
    bigintBIGINT
    realFLOAT
    float/money/smallmoneyDOUBLE
    decimal/numericDECIMAL
    dateDATE
    datetime/datetime2/smalldatetimeDATETIMEV2
    char/varchar/text/nchar/nvarchar/ntextSTRING
    binary/varbinarySTRING
    time/datetimeoffsetSTRING
    OtherUNSUPPORTED
    ClickHouse TypeDoris TypeComment
    BoolBOOLEAN
    StringSTRING
    Date/Date32DATE
    DateTime/DateTime64DATETIMEData beyond the maximum precision of DateTime in Doris will be truncated.
    Float32FLOAT
    Float64DOUBLE
    Int8TINYINT
    Int16/UInt8SMALLINTDoris does not support UNSIGNED data types so UInt8 will be mapped to SMALLINT.
    Int32/UInt16INTDoris does not support UNSIGNED data types so UInt16 will be mapped to INT.
    Int64/Uint32BIGINTDoris does not support UNSIGNED data types so UInt32 will be mapped to BIGINT.
    Int128/UInt64LARGEINTDoris does not support UNSIGNED data types so UInt64 will be mapped to LARGEINT.
    Int256/UInt128/UInt256STRINGDoris does not support data types of such orders of magnitude so these will be mapped to STRING.
    DECIMALDECIMALData beyond the maximum decimal precision in Doris will be truncated.
    Enum/IPv4/IPv6/UUIDSTRINGData of IPv4 and IPv6 type will be displayed with an extra / as a prefix. To remove the /, you can use the split_partfunction.
    OtherUNSUPPORTED

    Doris

    FAQ

    1. Are there any other databases supported besides MySQL, Oracle, PostgreSQL, SQLServer, and ClickHouse?

      Currently, Doris supports MySQL, Oracle, PostgreSQL, SQLServer, and ClickHouse. We are planning to expand this list. Technically, any databases that support JDBC access can be connected to Doris in the form of JDBC external tables. You are more than welcome to be a Doris contributor to expedite this effort.

    2. Why does the error message “CAUSED BY: DataReadException: Zero date value prohibited” pop up when DateTime=”0000:00:00 00:00:00” while reading MySQL external tables?

      The options for this parameter include: EXCEPTION,CONVERT_TO_NULL,ROUND. Respectively, they mean to report error, convert to null, and round the DateTime to “0001-01-01 00:00:00” when encountering an illegal DateTime.

      You can add "jdbc_url"="jdbc:mysql://IP:PORT/doris_test?zeroDateTimeBehavior=convertToNull" to the URL.

    3. Why do loading failures happen when reading MySQL or other external tables?

      For example:

      1. failed to load driver class com.mysql.jdbc.driver in either of hikariconfig class loader

      Such errors occur because the driver_class has been wrongly put when creating the Resource. The problem with the above example is the letter case. It should be corrected as "driver_class" = "com.mysql.jdbc.Driver".

    4. How to fix communication link failures?

      If you run into the following errors:

      1. ERROR 1105 (HY000): errCode = 2, detailMessage = PoolInitializationException: Failed to initialize pool: Communications link failure
      2. The last packet successfully received from the server was 7 milliseconds ago. The last packet sent successfully to the server was 4 milliseconds ago.
      3. CAUSED BY: CommunicationsException: Communications link failure
      4. The last packet successfully received from the server was 7 milliseconds ago. The last packet sent successfully to the server was 4 milliseconds ago.
      5. CAUSED BY: SSLHandshakeExcepti

      Please check the be.out log of BE.

      If it contains the following message:

      You can add ?useSSL=false to the end of the JDBC connection string when creating Catalog. For example, "jdbc_url" = "jdbc:mysql://127.0.0.1:3306/test?useSSL=false".

    5. What to do with errors such as “CAUSED BY: SQLException OutOfMemoryError” when performing JDBC queries?