Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
dengzhhu653 committed Feb 23, 2024
1 parent 089ee48 commit 075da06
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -759,22 +759,6 @@ public Object getBoolean(boolean val) {
return val;
}

public Object convertDateValue(Object dateValue) {
assert dateValue instanceof String;
Date date = MetaStoreUtils.convertStringToDate((String)dateValue);
Object result = MetaStoreUtils.convertDateToString(date);
return result;
}

public Object convertTimestampValue(Object timestampValue) {
assert timestampValue instanceof String;
MetaStoreUtils.convertStringToTimestamp((String) timestampValue);
// The timestampValue looks valid now, for Postgres/SQLServer/Oracle, return timestampValue as it is,
// otherwise we may run into different results on SQL and JDO, check the partition_timestamp3.q
// for such case.
return timestampValue;
}

/**
* Get the max rows in a query with paramSize.
* @param batch the configured batch size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,9 @@ public void visit(LeafNode node) throws MetaException {
// type mismatch when string col is filtered by a string that looks like date.
if (colType == FilterType.Date) {
try {
nodeValue = dbType.convertDateValue(nodeValue);
// check the nodeValue is a valid date
nodeValue = MetaStoreUtils.convertDateToString(
MetaStoreUtils.convertStringToDate((String) nodeValue));
valType = FilterType.Date;
if (dbType.isPOSTGRES() || dbType.isORACLE()) {
nodeValue0 = "date '" + nodeValue + "'";
Expand All @@ -1437,18 +1439,18 @@ public void visit(LeafNode node) throws MetaException {
}
} else if (colType == FilterType.Timestamp) {
if (dbType.isDERBY() || dbType.isMYSQL()) {
filterBuffer.setError("Filter pushdown not supported for timestamp on " + dbType.dbType.name());
filterBuffer.setError("Filter pushdown on timestamp not supported for " + dbType.dbType.name());
return;
}
try {
nodeValue = dbType.convertTimestampValue(nodeValue);
// check the nodeValue is a valid timestamp
MetaStoreUtils.convertStringToTimestamp((String) nodeValue);
valType = FilterType.Timestamp;
if (dbType.isPOSTGRES() || dbType.isORACLE()) {
nodeValue0 = "timestamp '" + nodeValue + "'";
nodeValue = null;
}
} catch (Exception e) {
// The nodeValue could be '__HIVE_DEFAULT_PARTITION__'
} catch (Exception e) { //nodeValue could be '__HIVE_DEFAULT_PARTITION__'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;

import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;

/**
Expand Down Expand Up @@ -273,20 +274,12 @@ public String toString() {
*/
public static int getPartColIndexForFilter(String partitionKeyName,
List<FieldSchema> partitionKeys, FilterBuilder filterBuilder) throws MetaException {
assert (partitionKeys.size() > 0);
int partitionColumnIndex;
for (partitionColumnIndex = 0; partitionColumnIndex < partitionKeys.size();
++partitionColumnIndex) {
if (partitionKeys.get(partitionColumnIndex).getName().equalsIgnoreCase(partitionKeyName)) {
break;
}
}
if( partitionColumnIndex == partitionKeys.size()) {
int partitionColumnIndex = Iterables.indexOf(partitionKeys, key -> partitionKeyName.equalsIgnoreCase(key.getName()));
if( partitionColumnIndex < 0) {
filterBuilder.setError("Specified key <" + partitionKeyName +
"> is not a partitioning key for the table");
return -1;
}

return partitionColumnIndex;
}
}
Expand Down

0 comments on commit 075da06

Please sign in to comment.