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

feat: flink sql add create space #66

Merged
merged 6 commits into from
Aug 12, 2022

Conversation

liuxiaocs7
Copy link
Contributor

Try to close #62.

@codecov-commenter
Copy link

codecov-commenter commented Jul 13, 2022

Codecov Report

Merging #66 (8e4435f) into master (93df7a1) will increase coverage by 11.82%.
The diff coverage is 63.20%.

@@              Coverage Diff              @@
##             master      #66       +/-   ##
=============================================
+ Coverage     49.72%   61.54%   +11.82%     
- Complexity      190      291      +101     
=============================================
  Files            50       52        +2     
  Lines          1613     1784      +171     
  Branches        153      166       +13     
=============================================
+ Hits            802     1098      +296     
+ Misses          743      596      -147     
- Partials         68       90       +22     
Impacted Files Coverage Δ
...onnector/nebula/catalog/AbstractNebulaCatalog.java 26.56% <33.33%> (+26.56%) ⬆️
...ache.flink/connector/nebula/utils/NebulaSpace.java 47.05% <47.05%> (ø)
....flink/connector/nebula/catalog/NebulaCatalog.java 29.29% <57.81%> (+29.29%) ⬆️
...che.flink/connector/nebula/utils/NebulaSpaces.java 91.30% <91.30%> (ø)
...ink/connector/nebula/utils/NebulaCatalogUtils.java 50.00% <100.00%> (+50.00%) ⬆️
...e.flink/connector/nebula/utils/NebulaConstant.java 95.00% <100.00%> (+0.55%) ⬆️
...ache.flink/connector/nebula/utils/NebulaUtils.java 74.60% <100.00%> (+2.67%) ⬆️
...ebula/connection/NebulaMetaConnectionProvider.java 55.55% <0.00%> (ø)
...connector/nebula/table/NebulaRowDataConverter.java 59.52% <0.00%> (ø)
...nnector/nebula/connection/NebulaClientOptions.java 91.25% <0.00%> (+1.25%) ⬆️
... and 12 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@liuxiaocs7
Copy link
Contributor Author

Refer to Flink SQL doc and Nebula doc.

CREATE DATABASE [IF NOT EXISTS] [catalog_name.]db_name
  [COMMENT database_comment]
  WITH (key1=val1, key2=val2, ...)
CREATE SPACE [IF NOT EXISTS] <graph_space_name> (
    [partition_num = <partition_number>,]
    [replica_factor = <replica_number>,]
    vid_type = {FIXED_STRING(<N>) | INT[64]}
    )
    [COMMENT = '<comment>'];

I register the NebulaCatalog to flink table environment and use the catalog. Then execute create database statement will go to createDatabase method. In this method, we use graph client to execute create space ngql statement.

Test Environment:

Windows Virtual Machine(Centos7), Nebula is deployed by Docker.

And result is just as follow:

Snipaste_2022-07-14_00-21-38

* @param b true if contains [if not exists] else false
*/
@Override
public void createDatabase(String s, CatalogDatabase catalogDatabase, boolean b)
Copy link
Contributor

Choose a reason for hiding this comment

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

please use more meaningful variable name for s and b.
eg: dataBaseName, useIfNotExists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, these variable name is so bad. I'll change them. And should i change the variable names in the method it inherits.

In AbstractNebulaCatalog, the method definition looks like this:

@Override
public void createDatabase(String s, CatalogDatabase catalogDatabase, boolean b)
        throws CatalogException {
    throw new UnsupportedOperationException();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

great catch, the parent method has bad variable names, please change it too, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for my late reply, this week i am many other things to do, i am glad to do this as soon as possible

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 9e2c2b5 commit update the bad variable names in AbstractNebulaCatalog

LOG.debug("create space success.");
} else {
LOG.error("create space failed: {}", execResult.getErrorMessage());
throw new CatalogException("create space failed.");
Copy link
Contributor

Choose a reason for hiding this comment

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

append the error message of execResult

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it means to append execResult error message to CatalogException message?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it, e23cdfd should sovle this i think, thanks for your kindly suggestion.

checkArgument(
!StringUtils.isNullOrWhitespaceOnly(address),
"address cannot be null or empty."
);
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for the todo work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my pleasure.

!isNullOrWhitespaceOnly(dataBaseName), "space name cannot be null or empty.");
checkNotNull(catalogDatabase, "space cannot be null.");

if (ignoreIfExists && listDatabases().contains(dataBaseName)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

from the view of product consistency, if ignoreIfExists is true, we should also give the positive feedback.

For Nebula, if a space exists, we'll get SUCCEED when create a repeated space, even though they have different properties, such as vid_type.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, there are indeed logical inconsistencies, i'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the doc
image

Now, if the space has already existed and create the space with IF NOT EXISTS clause it will do nothing. just as
ded8300.

Test Result:

 INFO [main] - Repeat to create space, db1 already exists, no effect.

Do you think it's OK to revise this way?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's fine, thanks for this kindly log info.

Copy link
Contributor

@Nicole00 Nicole00 left a comment

Choose a reason for hiding this comment

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

LGTM

@Nicole00 Nicole00 merged commit 677ed77 into vesoft-inc:master Aug 12, 2022
@liuxiaocs7 liuxiaocs7 deleted the create_space branch September 28, 2022 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FlinkSQL support: CREATE SPACE
3 participants