fix chinese in column and row (#2216)

* charset for atk-1406 (#2200)

* charset for atk-1409, missing for atk-1408 (#2202)

* charset for atk-1400 (#2198)
This commit is contained in:
Collapsar
2020-11-02 18:54:01 +08:00
committed by GitHub
parent 11ea9e2656
commit 0f4d5fdc22
7 changed files with 49 additions and 15 deletions
@@ -221,6 +221,7 @@ public final class HandlerTool {
args.add(newArg);
}
ItemFunc ret = (ItemFunc) f.reStruct(args, allPushDown, fields);
ret.setCharsetIndex(f.getCharsetIndex());
ret.setItemName(f.getPushDownName() == null ? f.getItemName() : f.getPushDownName());
return ret;
}
@@ -265,7 +266,7 @@ public final class HandlerTool {
int index = findField(col, fields, startIndex);
if (index < 0)
throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "field not found:" + col);
ItemField ret = new ItemField(fields.get(index));
ItemField ret = new ItemField(fields.get(index), col.getCharsetIndex());
ret.setItemName(col.getPushDownName() == null ? col.getItemName() : col.getPushDownName());
return ret;
}
@@ -16,6 +16,7 @@ public class NamedField {
private final int hashCode;
// which node of the field belong
public final PlanNode planNode;
private int charsetIndex;
public NamedField(String inputSchema, String inputTable, String name, PlanNode planNode) {
String tempTableSchmea;
@@ -57,6 +58,14 @@ public class NamedField {
return name;
}
public int getCharsetIndex() {
return charsetIndex;
}
public void setCharsetIndex(int charsetIndex) {
this.charsetIndex = charsetIndex;
}
@Override
public boolean equals(Object obj) {
if (obj == null)
@@ -35,6 +35,11 @@ public class ItemField extends ItemIdent {
/* if index!=-1, means the index of Item_field,need setField before val */
private int index = -1;
public ItemField(String dbName, String tableName, String fieldName, int charsetIndex) {
super(dbName, tableName, fieldName);
this.charsetIndex = charsetIndex;
}
public ItemField(String dbName, String tableName, String fieldName) {
super(dbName, tableName, fieldName);
}
@@ -44,6 +49,11 @@ public class ItemField extends ItemIdent {
setField(field);
}
public ItemField(Field field, int charsetIndex) {
this(field);
this.charsetIndex = charsetIndex;
}
/**
* save index
*
@@ -337,7 +347,7 @@ public class ItemField extends ItemIdent {
@Override
protected Item cloneStruct(boolean forCalculate, List<Item> calArgs, boolean isPushDown, List<Field> fields) {
return new ItemField(dbName, tableName, itemName);
return new ItemField(dbName, tableName, itemName, charsetIndex);
}
public Field getField() {
@@ -257,6 +257,7 @@ public abstract class PlanNode {
for (Item selected : this.getColumnsSelected()) {
Item copySel = selected.cloneItem();
copySel.setItemName(selected.getItemName());
copySel.setCharsetIndex(selected.getCharsetIndex());
to.columnsSelected.add(copySel);
}
for (Order groupBy : this.getGroupBys()) {
@@ -399,7 +400,7 @@ public abstract class PlanNode {
protected void dealSingleStarColumn(List<Item> newSels) {
for (NamedField field : innerFields.keySet()) {
ItemField col = new ItemField(field.getSchema(), field.getTable(), field.getName());
ItemField col = new ItemField(field.getSchema(), field.getTable(), field.getName(), field.getCharsetIndex());
newSels.add(col);
}
}
@@ -416,7 +417,7 @@ public abstract class PlanNode {
boolean found = false;
for (NamedField field : innerFields.keySet()) {
if (selTable.equals(field.getTable())) {
ItemField col = new ItemField(field.getSchema(), field.getTable(), field.getName());
ItemField col = new ItemField(field.getSchema(), field.getTable(), field.getName(), field.getCharsetIndex());
newSels.add(col);
found = true;
} else if (found) {
@@ -31,6 +31,8 @@ public class TableNode extends PlanNode {
private StructureMeta.TableMeta tableMeta;
private List<String> columns;
private List<SQLHint> hintList;
private int charsetIndex;
private TableNode() {
}
@@ -55,9 +57,10 @@ public class TableNode extends PlanNode {
this.keepFieldSchema = true;
}
public TableNode(String catalog, String tableName, ProxyMetaManager metaManager) throws SQLNonTransientException {
public TableNode(String catalog, String tableName, ProxyMetaManager metaManager, int charsetIndex) throws SQLNonTransientException {
if (catalog == null || tableName == null)
throw new RuntimeException("Table db or name is null error!");
this.charsetIndex = charsetIndex;
this.schema = catalog;
this.tableName = tableName;
ServerConfig config = DbleServer.getInstance().getConfig();
@@ -115,11 +118,13 @@ public class TableNode extends PlanNode {
if (tableMeta != null) {
for (StructureMeta.ColumnMeta cm : tableMeta.getColumnsList()) {
NamedField tmpField = new NamedField(schema, tmpTable, cm.getName(), this);
tmpField.setCharsetIndex(charsetIndex);
innerFields.put(tmpField, tmpField);
}
} else {
for (String col : columns) {
NamedField tmpField = new NamedField(schema, tmpTable, col, this);
tmpField.setCharsetIndex(charsetIndex);
innerFields.put(tmpField, tmpField);
}
}
@@ -134,7 +139,7 @@ public class TableNode extends PlanNode {
newSelects.add(sel);
else {
for (NamedField innerField : innerFields.keySet()) {
ItemField col = new ItemField(null, sel.getTableName(), innerField.getName());
ItemField col = new ItemField(null, sel.getTableName(), innerField.getName(), charsetIndex);
newSelects.add(col);
}
}
@@ -148,6 +153,7 @@ public class TableNode extends PlanNode {
newTableNode.tableName = this.tableName;
newTableNode.tableMeta = this.tableMeta == null ? null : this.tableMeta.toBuilder().build();
newTableNode.columns = this.columns;
newTableNode.charsetIndex = this.charsetIndex;
newTableNode.referedTableNodes.add(newTableNode);
newTableNode.setNoshardNode(this.getNoshardNode());
@@ -207,4 +213,11 @@ public class TableNode extends PlanNode {
this.hintList = hintList;
}
public int getCharsetIndex() {
return charsetIndex;
}
public void setCharsetIndex(int charsetIndex) {
this.charsetIndex = charsetIndex;
}
}
@@ -369,7 +369,7 @@ public class MySQLItemVisitor extends MySqlASTVisitorAdapter {
@Override
public void endVisit(SQLAllColumnExpr x) {
item = new ItemField(null, null, "*");
item = new ItemField(null, null, "*", charsetIndex);
initName(x);
}
@@ -441,7 +441,7 @@ public class MySQLItemVisitor extends MySqlASTVisitorAdapter {
@Override
public void endVisit(SQLIdentifierExpr x) {
item = new ItemField(null, null, StringUtil.removeBackQuote(x.getSimpleName()));
item = new ItemField(null, null, StringUtil.removeBackQuote(x.getSimpleName()), charsetIndex);
}
@Override
@@ -506,10 +506,9 @@ public class MySQLItemVisitor extends MySqlASTVisitorAdapter {
item = new ItemNull();
initName(x);
}
} else {
item = new ItemVariables(x.getName(), new ItemField(null, null, variable));
initName(x);
}
item = new ItemVariables(x.getName(), new ItemField(null, null, variable, charsetIndex));
initName(x);
}
@Override
@@ -523,7 +522,7 @@ public class MySQLItemVisitor extends MySqlASTVisitorAdapter {
} else {
tableName = ((SQLIdentifierExpr) x.getOwner()).getSimpleName();
}
item = new ItemField(dbName, StringUtil.removeBackQuote(tableName), StringUtil.removeBackQuote(x.getSimpleName()));
item = new ItemField(dbName, StringUtil.removeBackQuote(tableName), StringUtil.removeBackQuote(x.getSimpleName()), charsetIndex);
}
@Override
@@ -167,7 +167,7 @@ public class MySQLPlanNodeVisitor {
}
public boolean visit(SQLExprTableSource tableSource) {
PlanNode table;
TableNode table;
String schema;
String tableName;
SQLExpr expr = tableSource.getExpr();
@@ -215,12 +215,12 @@ public class MySQLPlanNodeVisitor {
return true;
} else {
try {
table = new TableNode(schema, tableName, this.metaManager);
table = new TableNode(schema, tableName, this.metaManager, charsetIndex);
} catch (SQLNonTransientException e) {
throw new MySQLOutPutException(e.getErrorCode(), e.getSQLState(), e.getMessage());
}
}
((TableNode) table).setHintList(tableSource.getHints());
table.setHintList(tableSource.getHints());
this.tableNode = table;
return true;
}
@@ -358,6 +358,7 @@ public class MySQLPlanNodeVisitor {
MySQLItemVisitor ev = new MySQLItemVisitor(currentDb, this.charsetIndex, this.metaManager, this.usrVariables);
expr.accept(ev);
Item selItem = ev.getItem();
selItem.setCharsetIndex(charsetIndex);
if (selItem.isWithSubQuery()) {
setSubQueryNode(selItem);
}