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

[fix][dingo-executor] Fix dingodb version and create unique index replica issues #1267

Merged
merged 2 commits into from
Oct 22, 2024
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
9 changes: 8 additions & 1 deletion dingo-calcite/src/main/codegen/includes/parserImpls.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ void TableElement(List<SqlNode> list) :
list.add(new DingoSqlKeyConstraint(s.end(columnList), name, columnList));
}
[<USING> <IDENTIFIER> ]
[
<REPLICA> <EQ> {replica = Integer.parseInt(getNextToken().image);}
]
|
<PRIMARY> { s.add(this); } <KEY>
columnList = ParenthesizedSimpleIdentifierList() {
Expand Down Expand Up @@ -633,6 +636,7 @@ SqlCreate SqlCreateIndex(Span s, boolean replace) :
SqlIdentifier table;
SqlIdentifier column;
List<SqlIdentifier> columns;
int replica = 0;
SqlNode create = null;
Boolean ifNotExists = false;
}
Expand All @@ -648,8 +652,11 @@ SqlCreate SqlCreateIndex(Span s, boolean replace) :
column = SimpleIdentifier() { columns.add(column); }
)*
<RPAREN>
[
<REPLICA> <EQ> {replica = Integer.parseInt(getNextToken().image);}
]
{
return new SqlCreateIndex(s.end(this), replace, ifNotExists, index, table, columns, isUnique);
return new SqlCreateIndex(s.end(this), replace, ifNotExists, index, table, columns, isUnique, replica);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ public void execute(@NonNull SqlCreateIndex sqlCreateIndex, CalcitePrepare.Conte
null,
null,
null,
0,
sqlCreateIndex.replica,
"scalar",
"TXN_LSM"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,24 @@ public class SqlCreateIndex extends SqlCreate {

public boolean isUnique;

public int replica;

private static final SqlOperator OPERATOR =
new SqlSpecialOperator("CREATE INDEX", SqlKind.OTHER_DDL);

public SqlCreateIndex(SqlParserPos pos, boolean replace, boolean ifNotExists,
String index,
SqlIdentifier table,
List<SqlIdentifier> columns,
boolean isUnique) {
boolean isUnique, int replica) {
super(OPERATOR, pos, replace, ifNotExists);
this.index = index;
this.table = table;
this.columns = columns.stream()
.map(SqlIdentifier::getSimple)
.map(String::toUpperCase).collect(Collectors.toList());
this.isUnique = isUnique;
this.replica = replica;
}

@Override
Expand Down
37 changes: 22 additions & 15 deletions dingo-exec/src/main/java/io/dingodb/exec/fun/mysql/VersionFun.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.dingodb.exec.fun.mysql;

import com.ibm.icu.impl.data.ResourceReader;
import io.dingodb.common.log.LogUtils;
import io.dingodb.expr.runtime.EvalContext;
import io.dingodb.expr.runtime.ExprConfig;
import io.dingodb.expr.runtime.op.NullaryOp;
Expand All @@ -34,28 +35,34 @@
public class VersionFun extends NullaryOp {
public static final VersionFun INSTANCE = new VersionFun();
public static final String NAME = "version";
public static final String PRE = "5.7.41-DingoDB-";

public static String version = "UNKNOWN";
private static final long serialVersionUID = -4130064040675181327L;

@Override
public Object eval(EvalContext context, ExprConfig config) {
String version;
InputStream inputStream = ResourceReader.class.getResourceAsStream("/versiontmp.properties");
if (inputStream != null) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
static {
try {
InputStream inputStream = ResourceReader.class.getResourceAsStream("/versiontmp.properties");
if (inputStream != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
if(line.contains("=")){
version = line.split("=")[1].toString();
return version;
};
if(line.contains("=")){
version = PRE + line.split("=")[1].toString();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} else {
LogUtils.debug(log, "Failed to get current release version");
}
} else {
log.debug("Failed to get current release version");
} catch (Exception e) {
LogUtils.error(log, e.getMessage(), e);
}
return null;
}

@Override
public Object eval(EvalContext context, ExprConfig config) {
return version;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.dingodb.common.table.TableDefinition;
import io.dingodb.common.tenant.TenantConstant;
import io.dingodb.common.util.ByteArrayUtils;
import io.dingodb.exec.fun.mysql.VersionFun;
import io.dingodb.partition.DingoPartitionServiceProvider;
import io.dingodb.sdk.service.VersionService;
import io.dingodb.sdk.service.entity.meta.DingoCommonId;
Expand Down Expand Up @@ -252,7 +253,7 @@ public static List<Object[]> getGlobalVariablesList() {
values.add(new Object[]{"net_write_timeout", "60"});
values.add(new Object[]{"net_read_timeout", "60"});
values.add(new Object[]{"lower_case_table_names", "0"});
values.add(new Object[]{"version", "5.7.24"});
values.add(new Object[]{"version", VersionFun.version});
values.add(new Object[]{"version_compile_os", "Linux"});
values.add(new Object[]{"version_compile_machine", "x86_64"});
values.add(new Object[]{"init_connect", ""});
Expand Down
Loading