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

Add database engine of MySQL type #5599

Merged
merged 4 commits into from Jun 15, 2019

Conversation

zhang2014
Copy link
Contributor

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Category:

  • New Feature

Detailed description (optional):

It doesn't make any manipulations with filesystem.
All tables are created by calling code after real-time pull-out structure from remote MySQL

TCeason and others added 2 commits June 10, 2019 15:51
Co-authored-by: zhang2014 <coswde@gmail.com>
Co-authored-by: TCeason <tai_chong@foxmail.com>
@zhang2014
Copy link
Contributor Author

zhang2014 commented Jun 13, 2019

There was no way to determine from the returned log whether the error was related to the modification, and I need some help.

BTW, is there more information with the other two pending tests?

@alexey-milovidov
Copy link
Member

Now everything is green.

@alexey-milovidov alexey-milovidov added the pr-feature Pull request with new product feature label Jun 13, 2019
{
std::stringstream ostr;
formatAST(*engine_define, ostr, false, false);
throw Exception("Unknown database engine: " + ostr.str(), ErrorCodes::UNKNOWN_DATABASE_ENGINE);
Copy link
Member

Choose a reason for hiding this comment

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

You can make error message more descriptive, like "Database engine XYZ cannot have arguments".

PS. And parameters, primary_key, order_by, sample_by, settings should not ever be in CREATE DATABASE statement.

@@ -0,0 +1,22 @@
#pragma once
Copy link
Member

Choose a reason for hiding this comment

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

The file name is too generic. You can name it convertMySQLDataType.

namespace DB
{

ASTPtr getDataTypeAST(const DataTypePtr & data_type);
Copy link
Member

Choose a reason for hiding this comment

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

Non-descriptive function name.
Missing comments.

Copy link
Member

Choose a reason for hiding this comment

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

(the method name was Ok before, because it was hidden inside single cpp file)


else if (engine_name == "MySQL")
{
ASTFunction * engine = engine_define->engine;
Copy link
Member

Choose a reason for hiding this comment

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

const?

@@ -2,6 +2,7 @@

#include <Common/ThreadPool.h>
#include <Databases/IDatabase.h>
#include <Parsers/ASTCreateQuery.h>
Copy link
Member

Choose a reason for hiding this comment

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

It's not necessarily to include header, because you can use forward declaration.

}
}

cond.wait_for(lock, cleaner_sleep_time, quit_requested);
Copy link
Member

Choose a reason for hiding this comment

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

You can move it in a while condition, making quit_requested lambda unneeded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might make the code less readable ?

Copy link
Member

Choose a reason for hiding this comment

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

But now it looks redundant.


static constexpr const std::chrono::seconds cleaner_sleep_time{30};

String toQueryStringWithQuote(const std::vector<String> &quote_list)
Copy link
Member

Choose a reason for hiding this comment

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

Style (whitespace around &)

* It doesn't make any manipulations with filesystem.
* All tables are created by calling code after real-time pull-out structure from remote MySQL
*/
class DatabaseMySQL : public IDatabase
Copy link
Member

Choose a reason for hiding this comment

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

BTW, how it was working without cache?

Copy link
Contributor Author

@zhang2014 zhang2014 Jun 14, 2019

Choose a reason for hiding this comment

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

The current way of working is not very efficient. Currently, a simple query(no join, no subquery) will call the tryGetStorage method five or six times.

The MySQL database engine attempts to query MySQL system tables every time tryGetStorage is called. This will exist the following scenarios:

  • exist in cache & no exist in mysql : Move tables to outdated list for asynchronous drop.
  • no exist in cache & exist in mysql : Create tables and add to cache.
  • exist in cache & exist in mysql, but table structure are updated: Execute both cases simultaneously

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what would happen if you returned different storage to the same query. Maybe we should write a test ?

Copy link
Member

Choose a reason for hiding this comment

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

Ok, the cache is reasonable.

@@ -76,13 +76,13 @@ class DatabaseWithOwnTablesBase : public IDatabase
public:
bool isTableExist(
const Context & context,
const String & table_name) const override;
const String & table_name) override;
Copy link
Member

Choose a reason for hiding this comment

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

I don't like removing const from methods... maybe it is better to make cache mutable.

@@ -164,6 +115,9 @@ StoragePtr TableFunctionMySQL::executeImpl(const ASTPtr & ast_function, const Co

}

if (columns.empty())
throw Exception("MySQL table " + database_name + "." + table_name + " doesn't exist..", ErrorCodes::UNKNOWN_TABLE);
Copy link
Member

Choose a reason for hiding this comment

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

exist.. - Two dots.

@@ -164,6 +115,9 @@ StoragePtr TableFunctionMySQL::executeImpl(const ASTPtr & ast_function, const Co

}

if (columns.empty())
throw Exception("MySQL table " + database_name + "." + table_name + " doesn't exist..", ErrorCodes::UNKNOWN_TABLE);
Copy link
Member

Choose a reason for hiding this comment

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

backQuoteIfNeed

Copy link
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

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

Almost Ok, just a few questions remain.

(*block.getByPosition(1).column)[i].safeGet<String>(),
(*block.getByPosition(2).column)[i].safeGet<UInt64>() && context.getSettings().external_table_functions_use_nulls,
(*block.getByPosition(3).column)[i].safeGet<UInt64>(),
(*block.getByPosition(4).column)[i].safeGet<UInt64>()));

}

if (columns.empty())
throw Exception("MySQL table `" + database_name + "`.`" + table_name + "` doesn't exist.", ErrorCodes::UNKNOWN_TABLE);
Copy link
Member

Choose a reason for hiding this comment

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

But there is a function named backQuoteIfNeed that will also do proper escaping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature Pull request with new product feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants