qidaye commented on code in PR #9593:
URL: https://github.com/apache/incubator-doris/pull/9593#discussion_r874609723
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/HiveTable.java:
##########
@@ -74,6 +89,98 @@ public Map<String, String> getHiveProperties() {
return hiveProperties;
}
+ @Override
+ public List<Column> getBaseSchema(boolean full) {
+ if (isLocalSchema) {
+ return super.getBaseSchema(full);
+ }
+ List<Column> hiveMetastoreSchema = Lists.newArrayList();
+ try {
+ for (FieldSchema field :
HiveMetaStoreClientHelper.getSchema(this)) {
+ hiveMetastoreSchema.add(new Column(field.getName(),
convertToDorisType(field.getType()),
+ true, null, true, null, field.getComment()));
+ }
+ } catch (DdlException e) {
+ LOG.warn("Failed to get schema of hive table. DB {}, Table {}. {}",
+ this.hiveDb, this.hiveTable, e.getMessage());
+ return null;
+ }
+ fullSchema = hiveMetastoreSchema;
+ return fullSchema;
+ }
+
+ @Override
+ public Column getColumn(String name) {
+ if (isLocalSchema) {
+ return nameToColumn.get(name);
+ }
+ Column col = null;
+ if (fullSchema == null || fullSchema.size() == 0) {
+ getBaseSchema(true);
+ }
+ for (Column column : fullSchema) {
+ if (column.getName().equals(name)) {
+ return column;
+ }
+ }
+ return col;
+ }
+
+ private Type convertToDorisType(String hiveType) {
+ String lowerCaseType = hiveType.toLowerCase();
+ if (lowerCaseType.equals("boolean")) {
+ return Type.BOOLEAN;
+ }
+ if (lowerCaseType.equals("tinyint")) {
+ return Type.TINYINT;
+ }
+ if (lowerCaseType.equals("smallint")) {
+ return Type.SMALLINT;
+ }
+ if (lowerCaseType.equals("int")) {
+ return Type.INT;
+ }
+ if (lowerCaseType.equals("bigint")) {
+ return Type.BIGINT;
+ }
+ if (lowerCaseType.startsWith("char")) {
+ ScalarType type = ScalarType.createType(PrimitiveType.CHAR);
+ Matcher match = digitPattern.matcher(lowerCaseType);
+ if (match.find()) {
+ type.setLength(Integer.parseInt(match.group(1)));
+ }
+ return type;
+ }
+ if (lowerCaseType.startsWith("varchar")) {
+ ScalarType type = ScalarType.createType(PrimitiveType.VARCHAR);
+ Matcher match = digitPattern.matcher(lowerCaseType);
+ if (match.find()) {
+ type.setLength(Integer.parseInt(match.group(1)));
+ }
+ return type;
+ }
+ if (lowerCaseType.startsWith("decimal")) {
+ Matcher match = digitPattern.matcher(lowerCaseType);
+ int precision = ScalarType.DEFAULT_PRECISION;
+ int scale = ScalarType.DEFAULT_SCALE;
+ if (match.find()) {
+ precision = Integer.parseInt(match.group(1));
+ }
+ if (match.find()) {
+ scale = Integer.parseInt(match.group(1));
+ }
+ return ScalarType.createDecimalV2Type(precision, scale);
+ }
+ if (lowerCaseType.equals("date")) {
+ return Type.DATE;
+ }
+ if (lowerCaseType.equals("datetime")) {
Review Comment:
```suggestion
if (lowerCaseType.equals("timestamp")) {
```
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/HiveTable.java:
##########
@@ -74,6 +89,92 @@ public Map<String, String> getHiveProperties() {
return hiveProperties;
}
+ @Override
+ public List<Column> getBaseSchema(boolean full) {
+ if (isLocalSchema) {
+ return super.getBaseSchema(full);
+ }
+ List<Column> hiveMetastoreSchema = Lists.newArrayList();
+ try {
+ for (FieldSchema field :
HiveMetaStoreClientHelper.getSchema(this)) {
+ field.getType();
+ hiveMetastoreSchema.add(new Column(field.getName(),
convertToDorisType(field.getType()),
+ true, null, true, null, field.getComment()));
+ }
+ } catch (DdlException e) {
+ LOG.warn("Failed to get schema of hive table. DB {}, Table {}. {}",
+ this.hiveDb, this.hiveTable, e.getMessage());
+ return null;
+ }
+ fullSchema = hiveMetastoreSchema;
+ return fullSchema;
+ }
+
+ public Column getColumn(String name) {
Review Comment:
OK
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]