1
1
package com .amazonaws .glue .catalog .converters ;
2
2
3
- import com .amazonaws .glue .catalog .metastore .AWSGlueClientFactory ;
4
- import org .apache .commons .lang3 .StringUtils ;
5
3
import com .amazonaws .services .glue .model .Table ;
6
-
7
4
import com .google .gson .Gson ;
5
+ import org .apache .commons .lang3 .StringUtils ;
8
6
import org .apache .hadoop .hive .metastore .HiveMetaStore ;
9
7
import org .apache .hadoop .hive .metastore .PartFilterExprUtil ;
10
8
import org .apache .hadoop .hive .metastore .api .MetaException ;
11
9
import org .apache .hadoop .hive .metastore .parser .ExpressionTree ;
12
- import org .apache .hadoop .hive .serde .serdeConstants ;
13
10
import org .apache .log4j .Logger ;
14
11
15
12
public class ConverterUtils {
@@ -40,22 +37,19 @@ public static String convertLocationScheme(String location, String targetScheme)
40
37
public static class PartitionFilterConverter extends ExpressionTree .TreeVisitor {
41
38
private static final Logger logger = Logger .getLogger (PartitionFilterConverter .class );
42
39
43
- // Need to be convert to hive metastore api model
44
- private final org .apache .hadoop .hive .metastore .api .Table table ;
45
40
private final ExpressionTree .FilterBuilder filterBuffer ;
46
41
47
- private PartitionFilterConverter (Table table , String dbname ) {
48
- this .table = CatalogToHiveConverter .convertTable (table , dbname );
42
+ private PartitionFilterConverter () {
49
43
this .filterBuffer = new ExpressionTree .FilterBuilder (false );
50
44
}
51
45
52
46
// hive 에서 넘어온 partition filter expr을 glue catalog 맥락으로 전환
53
47
// 이 과정에서 모종의 이슈가 발생 할 경우 로그로 정보만 남기고 null 리턴 (이 경우 partition pruning을 하지 않도록 fallback)
54
- public static String convertHiveToCatalog (Table table , String dbname , String filter ) {
48
+ public static String convertHiveToCatalog (String filter ) {
55
49
try {
56
50
final ExpressionTree tree = (filter != null && !filter .isEmpty ())
57
51
? PartFilterExprUtil .getFilterParser (filter ).tree : ExpressionTree .EMPTY_TREE ;
58
- PartitionFilterConverter visitor = new PartitionFilterConverter (table , dbname );
52
+ PartitionFilterConverter visitor = new PartitionFilterConverter ();
59
53
tree .accept (visitor );
60
54
61
55
// (kimtkyeom) TODO: Need to throw?
@@ -99,17 +93,6 @@ private static enum FilterType {
99
93
100
94
Invalid ;
101
95
102
- static FilterType fromType (String colTypeStr ) {
103
- if (colTypeStr .equals (serdeConstants .STRING_TYPE_NAME )) {
104
- return FilterType .String ;
105
- } else if (colTypeStr .equals (serdeConstants .DATE_TYPE_NAME )) {
106
- return FilterType .Date ;
107
- } else if (serdeConstants .IntegralTypes .contains (colTypeStr )) {
108
- return FilterType .Integral ;
109
- }
110
- return FilterType .Invalid ;
111
- }
112
-
113
96
public static FilterType fromClass (Object value ) {
114
97
if (value instanceof String ) {
115
98
return FilterType .String ;
@@ -124,16 +107,6 @@ public static FilterType fromClass(Object value) {
124
107
125
108
@ Override
126
109
public void visit (ExpressionTree .LeafNode node ) throws MetaException {
127
- int partColIndex = node .getPartColIndexForFilter (table , filterBuffer );
128
- if (filterBuffer .hasError ()) return ;
129
-
130
- // We skipped 'like', other ops should all work as long as the types are right.
131
- String colTypeStr = table .getPartitionKeys ().get (partColIndex ).getType ();
132
- FilterType colType = FilterType .fromType (colTypeStr );
133
- if (colType == FilterType .Invalid ) {
134
- filterBuffer .setError ("Filter pushdown not supported for type " + colTypeStr );
135
- return ;
136
- }
137
110
FilterType valType = FilterType .fromClass (node .value );
138
111
Object nodeValue = node .value ;
139
112
if (valType == FilterType .Invalid ) {
@@ -142,15 +115,11 @@ public void visit(ExpressionTree.LeafNode node) throws MetaException {
142
115
}
143
116
144
117
String partFilterExpr = "" ;
145
- if (colType == FilterType .Integral ) {
118
+ if (valType == FilterType .Integral ) {
146
119
partFilterExpr = node .keyName + node .operator .getOp () + node .value ;
147
- } else if (colType == FilterType .String ) {
148
- partFilterExpr = node .keyName + node .operator .getOp () + "'" + node .value + "'" ;
149
- } else if (colType == FilterType .Date && valType == FilterType .String ) {
150
- // (kimtkyeom) directSql 로 들어오는 partition pruning expr 중 string 형태로 filter value가 들어오는 경우가 있음.
151
- // Glue는 unquoted date str을 받지 않으므로 quote를 추가해주는 대응을 한다.
120
+ } else if (valType == FilterType .String ) {
152
121
partFilterExpr = node .keyName + node .operator .getOp () + "'" + node .value + "'" ;
153
- } else if (colType == FilterType . Date && valType == FilterType .Date ) {
122
+ } else if (valType == FilterType .Date ) {
154
123
// (kimtkyeom) Date type 필터가 date type value로 들어온 경우, string으로 format
155
124
String dateFormatted = HiveMetaStore .PARTITION_DATE_FORMAT .get ().format ((java .sql .Date ) nodeValue );
156
125
partFilterExpr = node .keyName + node .operator .getOp () + "'" + dateFormatted + "'" ;
0 commit comments