Index: metastore/ivy.xml =================================================================== --- metastore/ivy.xml (revision 991274) +++ metastore/ivy.xml (working copy) @@ -9,7 +9,7 @@ - + @@ -17,8 +17,9 @@ + - + @@ -27,13 +28,13 @@ - + - + @@ -41,7 +42,7 @@ - + Index: metastore/src/gen-py/hive_metastore/ThriftHiveMetastore.py =================================================================== --- metastore/src/gen-py/hive_metastore/ThriftHiveMetastore.py (revision 991274) +++ metastore/src/gen-py/hive_metastore/ThriftHiveMetastore.py (working copy) @@ -245,6 +245,16 @@ """ pass + def get_partitions_by_filter(self, db_name, tbl_name, filter, max_parts): + """ + Parameters: + - db_name + - tbl_name + - filter + - max_parts + """ + pass + def alter_partition(self, db_name, tbl_name, new_part): """ Parameters: @@ -1336,6 +1346,44 @@ raise result.o1 raise TApplicationException(TApplicationException.MISSING_RESULT, "get_partition_names_ps failed: unknown result"); + def get_partitions_by_filter(self, db_name, tbl_name, filter, max_parts): + """ + Parameters: + - db_name + - tbl_name + - filter + - max_parts + """ + self.send_get_partitions_by_filter(db_name, tbl_name, filter, max_parts) + return self.recv_get_partitions_by_filter() + + def send_get_partitions_by_filter(self, db_name, tbl_name, filter, max_parts): + self._oprot.writeMessageBegin('get_partitions_by_filter', TMessageType.CALL, self._seqid) + args = get_partitions_by_filter_args() + args.db_name = db_name + args.tbl_name = tbl_name + args.filter = filter + args.max_parts = max_parts + args.write(self._oprot) + self._oprot.writeMessageEnd() + self._oprot.trans.flush() + + def recv_get_partitions_by_filter(self, ): + (fname, mtype, rseqid) = self._iprot.readMessageBegin() + if mtype == TMessageType.EXCEPTION: + x = TApplicationException() + x.read(self._iprot) + self._iprot.readMessageEnd() + raise x + result = get_partitions_by_filter_result() + result.read(self._iprot) + self._iprot.readMessageEnd() + if result.success != None: + return result.success + if result.o1 != None: + raise result.o1 + raise TApplicationException(TApplicationException.MISSING_RESULT, "get_partitions_by_filter failed: unknown result"); + def alter_partition(self, db_name, tbl_name, new_part): """ Parameters: @@ -1692,6 +1740,7 @@ self._processMap["get_partition_names"] = Processor.process_get_partition_names self._processMap["get_partitions_ps"] = Processor.process_get_partitions_ps self._processMap["get_partition_names_ps"] = Processor.process_get_partition_names_ps + self._processMap["get_partitions_by_filter"] = Processor.process_get_partitions_by_filter self._processMap["alter_partition"] = Processor.process_alter_partition self._processMap["get_config_value"] = Processor.process_get_config_value self._processMap["partition_name_to_vals"] = Processor.process_partition_name_to_vals @@ -2169,6 +2218,20 @@ oprot.writeMessageEnd() oprot.trans.flush() + def process_get_partitions_by_filter(self, seqid, iprot, oprot): + args = get_partitions_by_filter_args() + args.read(iprot) + iprot.readMessageEnd() + result = get_partitions_by_filter_result() + try: + result.success = self._handler.get_partitions_by_filter(args.db_name, args.tbl_name, args.filter, args.max_parts) + except MetaException, o1: + result.o1 = o1 + oprot.writeMessageBegin("get_partitions_by_filter", TMessageType.REPLY, seqid) + result.write(oprot) + oprot.writeMessageEnd() + oprot.trans.flush() + def process_alter_partition(self, seqid, iprot, oprot): args = alter_partition_args() args.read(iprot) @@ -6643,6 +6706,175 @@ def __ne__(self, other): return not (self == other) +class get_partitions_by_filter_args: + """ + Attributes: + - db_name + - tbl_name + - filter + - max_parts + """ + + thrift_spec = ( + None, # 0 + (1, TType.STRING, 'db_name', None, None, ), # 1 + (2, TType.STRING, 'tbl_name', None, None, ), # 2 + (3, TType.STRING, 'filter', None, None, ), # 3 + (4, TType.I16, 'max_parts', None, -1, ), # 4 + ) + + def __init__(self, db_name=None, tbl_name=None, filter=None, max_parts=thrift_spec[4][4],): + self.db_name = db_name + self.tbl_name = tbl_name + self.filter = filter + self.max_parts = max_parts + + def read(self, iprot): + if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None: + fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec)) + return + iprot.readStructBegin() + while True: + (fname, ftype, fid) = iprot.readFieldBegin() + if ftype == TType.STOP: + break + if fid == 1: + if ftype == TType.STRING: + self.db_name = iprot.readString(); + else: + iprot.skip(ftype) + elif fid == 2: + if ftype == TType.STRING: + self.tbl_name = iprot.readString(); + else: + iprot.skip(ftype) + elif fid == 3: + if ftype == TType.STRING: + self.filter = iprot.readString(); + else: + iprot.skip(ftype) + elif fid == 4: + if ftype == TType.I16: + self.max_parts = iprot.readI16(); + else: + iprot.skip(ftype) + else: + iprot.skip(ftype) + iprot.readFieldEnd() + iprot.readStructEnd() + + def write(self, oprot): + if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: + oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) + return + oprot.writeStructBegin('get_partitions_by_filter_args') + if self.db_name != None: + oprot.writeFieldBegin('db_name', TType.STRING, 1) + oprot.writeString(self.db_name) + oprot.writeFieldEnd() + if self.tbl_name != None: + oprot.writeFieldBegin('tbl_name', TType.STRING, 2) + oprot.writeString(self.tbl_name) + oprot.writeFieldEnd() + if self.filter != None: + oprot.writeFieldBegin('filter', TType.STRING, 3) + oprot.writeString(self.filter) + oprot.writeFieldEnd() + if self.max_parts != None: + oprot.writeFieldBegin('max_parts', TType.I16, 4) + oprot.writeI16(self.max_parts) + oprot.writeFieldEnd() + oprot.writeFieldStop() + oprot.writeStructEnd() + + def __repr__(self): + L = ['%s=%r' % (key, value) + for key, value in self.__dict__.iteritems()] + return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) + + def __eq__(self, other): + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ + + def __ne__(self, other): + return not (self == other) + +class get_partitions_by_filter_result: + """ + Attributes: + - success + - o1 + """ + + thrift_spec = ( + (0, TType.LIST, 'success', (TType.STRUCT,(Partition, Partition.thrift_spec)), None, ), # 0 + (1, TType.STRUCT, 'o1', (MetaException, MetaException.thrift_spec), None, ), # 1 + ) + + def __init__(self, success=None, o1=None,): + self.success = success + self.o1 = o1 + + def read(self, iprot): + if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None: + fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec)) + return + iprot.readStructBegin() + while True: + (fname, ftype, fid) = iprot.readFieldBegin() + if ftype == TType.STOP: + break + if fid == 0: + if ftype == TType.LIST: + self.success = [] + (_etype220, _size217) = iprot.readListBegin() + for _i221 in xrange(_size217): + _elem222 = Partition() + _elem222.read(iprot) + self.success.append(_elem222) + iprot.readListEnd() + else: + iprot.skip(ftype) + elif fid == 1: + if ftype == TType.STRUCT: + self.o1 = MetaException() + self.o1.read(iprot) + else: + iprot.skip(ftype) + else: + iprot.skip(ftype) + iprot.readFieldEnd() + iprot.readStructEnd() + + def write(self, oprot): + if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: + oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) + return + oprot.writeStructBegin('get_partitions_by_filter_result') + if self.success != None: + oprot.writeFieldBegin('success', TType.LIST, 0) + oprot.writeListBegin(TType.STRUCT, len(self.success)) + for iter223 in self.success: + iter223.write(oprot) + oprot.writeListEnd() + oprot.writeFieldEnd() + if self.o1 != None: + oprot.writeFieldBegin('o1', TType.STRUCT, 1) + self.o1.write(oprot) + oprot.writeFieldEnd() + oprot.writeFieldStop() + oprot.writeStructEnd() + + def __repr__(self): + L = ['%s=%r' % (key, value) + for key, value in self.__dict__.iteritems()] + return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) + + def __eq__(self, other): + return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ + + def __ne__(self, other): + return not (self == other) + class alter_partition_args: """ Attributes: @@ -7014,10 +7246,10 @@ if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype220, _size217) = iprot.readListBegin() - for _i221 in xrange(_size217): - _elem222 = iprot.readString(); - self.success.append(_elem222) + (_etype227, _size224) = iprot.readListBegin() + for _i228 in xrange(_size224): + _elem229 = iprot.readString(); + self.success.append(_elem229) iprot.readListEnd() else: iprot.skip(ftype) @@ -7040,8 +7272,8 @@ if self.success != None: oprot.writeFieldBegin('success', TType.LIST, 0) oprot.writeListBegin(TType.STRING, len(self.success)) - for iter223 in self.success: - oprot.writeString(iter223) + for iter230 in self.success: + oprot.writeString(iter230) oprot.writeListEnd() oprot.writeFieldEnd() if self.o1 != None: @@ -7146,11 +7378,11 @@ if fid == 0: if ftype == TType.MAP: self.success = {} - (_ktype225, _vtype226, _size224 ) = iprot.readMapBegin() - for _i228 in xrange(_size224): - _key229 = iprot.readString(); - _val230 = iprot.readString(); - self.success[_key229] = _val230 + (_ktype232, _vtype233, _size231 ) = iprot.readMapBegin() + for _i235 in xrange(_size231): + _key236 = iprot.readString(); + _val237 = iprot.readString(); + self.success[_key236] = _val237 iprot.readMapEnd() else: iprot.skip(ftype) @@ -7173,9 +7405,9 @@ if self.success != None: oprot.writeFieldBegin('success', TType.MAP, 0) oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.success)) - for kiter231,viter232 in self.success.items(): - oprot.writeString(kiter231) - oprot.writeString(viter232) + for kiter238,viter239 in self.success.items(): + oprot.writeString(kiter238) + oprot.writeString(viter239) oprot.writeMapEnd() oprot.writeFieldEnd() if self.o1 != None: @@ -7807,11 +8039,11 @@ if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype236, _size233) = iprot.readListBegin() - for _i237 in xrange(_size233): - _elem238 = Index() - _elem238.read(iprot) - self.success.append(_elem238) + (_etype243, _size240) = iprot.readListBegin() + for _i244 in xrange(_size240): + _elem245 = Index() + _elem245.read(iprot) + self.success.append(_elem245) iprot.readListEnd() else: iprot.skip(ftype) @@ -7840,8 +8072,8 @@ if self.success != None: oprot.writeFieldBegin('success', TType.LIST, 0) oprot.writeListBegin(TType.STRUCT, len(self.success)) - for iter239 in self.success: - iter239.write(oprot) + for iter246 in self.success: + iter246.write(oprot) oprot.writeListEnd() oprot.writeFieldEnd() if self.o1 != None: @@ -7974,10 +8206,10 @@ if fid == 0: if ftype == TType.LIST: self.success = [] - (_etype243, _size240) = iprot.readListBegin() - for _i244 in xrange(_size240): - _elem245 = iprot.readString(); - self.success.append(_elem245) + (_etype250, _size247) = iprot.readListBegin() + for _i251 in xrange(_size247): + _elem252 = iprot.readString(); + self.success.append(_elem252) iprot.readListEnd() else: iprot.skip(ftype) @@ -8000,8 +8232,8 @@ if self.success != None: oprot.writeFieldBegin('success', TType.LIST, 0) oprot.writeListBegin(TType.STRING, len(self.success)) - for iter246 in self.success: - oprot.writeString(iter246) + for iter253 in self.success: + oprot.writeString(iter253) oprot.writeListEnd() oprot.writeFieldEnd() if self.o2 != None: Index: metastore/src/gen-py/hive_metastore/ThriftHiveMetastore-remote =================================================================== --- metastore/src/gen-py/hive_metastore/ThriftHiveMetastore-remote (revision 991274) +++ metastore/src/gen-py/hive_metastore/ThriftHiveMetastore-remote (working copy) @@ -49,6 +49,7 @@ print ' get_partition_names(string db_name, string tbl_name, i16 max_parts)' print ' get_partitions_ps(string db_name, string tbl_name, part_vals, i16 max_parts)' print ' get_partition_names_ps(string db_name, string tbl_name, part_vals, i16 max_parts)' + print ' get_partitions_by_filter(string db_name, string tbl_name, string filter, i16 max_parts)' print ' void alter_partition(string db_name, string tbl_name, Partition new_part)' print ' string get_config_value(string name, string defaultValue)' print ' partition_name_to_vals(string part_name)' @@ -274,6 +275,12 @@ sys.exit(1) pp.pprint(client.get_partition_names_ps(args[0],args[1],eval(args[2]),eval(args[3]),)) +elif cmd == 'get_partitions_by_filter': + if len(args) != 4: + print 'get_partitions_by_filter requires 4 args' + sys.exit(1) + pp.pprint(client.get_partitions_by_filter(args[0],args[1],args[2],eval(args[3]),)) + elif cmd == 'alter_partition': if len(args) != 3: print 'alter_partition requires 3 args' Index: metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java =================================================================== --- metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java (revision 991274) +++ metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java (working copy) @@ -31,6 +31,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.metastore.api.AlreadyExistsException; import org.apache.hadoop.hive.metastore.api.ConfigValSecurityException; import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.api.FieldSchema; @@ -968,4 +969,170 @@ } catch (InvalidOperationException e) { } } + + /** + * Tests for list partition by filter functionality. + * @throws Exception + */ + public void testPartitionFilter() throws Exception { + String dbName = "filterdb"; + String tblName = "filtertbl"; + + List vals = new ArrayList(2); + vals.add("p11"); + vals.add("p21"); + vals.add("p31"); + List vals2 = new ArrayList(2); + vals2.add("p11"); + vals2.add("p22"); + vals2.add("p31"); + List vals3 = new ArrayList(2); + vals3.add("p12"); + vals3.add("p21"); + vals3.add("p31"); + List vals4 = new ArrayList(2); + vals4.add("p12"); + vals4.add("p23"); + vals4.add("p31"); + List vals5 = new ArrayList(2); + vals5.add("p13"); + vals5.add("p24"); + vals5.add("p31"); + List vals6 = new ArrayList(2); + vals6.add("p13"); + vals6.add("p25"); + vals6.add("p31"); + + silentDropDatabase(dbName); + + Database db = new Database(); + db.setName(dbName); + client.createDatabase(db); + + ArrayList cols = new ArrayList(2); + cols.add(new FieldSchema("c1", Constants.STRING_TYPE_NAME, "")); + cols.add(new FieldSchema("c2", Constants.INT_TYPE_NAME, "")); + + ArrayList partCols = new ArrayList(2); + partCols.add(new FieldSchema("p1", Constants.STRING_TYPE_NAME, "")); + partCols.add(new FieldSchema("p2", Constants.STRING_TYPE_NAME, "")); + partCols.add(new FieldSchema("p3", Constants.INT_TYPE_NAME, "")); + + Table tbl = new Table(); + tbl.setDbName(dbName); + tbl.setTableName(tblName); + StorageDescriptor sd = new StorageDescriptor(); + tbl.setSd(sd); + sd.setCols(cols); + sd.setCompressed(false); + sd.setNumBuckets(1); + sd.setParameters(new HashMap()); + sd.setBucketCols(new ArrayList()); + sd.setSerdeInfo(new SerDeInfo()); + sd.getSerdeInfo().setName(tbl.getTableName()); + sd.getSerdeInfo().setParameters(new HashMap()); + sd.getSerdeInfo().getParameters() + .put(Constants.SERIALIZATION_FORMAT, "1"); + sd.setSortCols(new ArrayList()); + + tbl.setPartitionKeys(partCols); + client.createTable(tbl); + + tbl = client.getTable(dbName, tblName); + + add_partition(client, tbl, vals, "part1"); + add_partition(client, tbl, vals2, "part2"); + add_partition(client, tbl, vals3, "part3"); + add_partition(client, tbl, vals4, "part4"); + add_partition(client, tbl, vals5, "part5"); + add_partition(client, tbl, vals6, "part6"); + + checkFilter(client, dbName, tblName, "p1 = \"p11\"", 2); + checkFilter(client, dbName, tblName, "p1 = \"p12\"", 2); + checkFilter(client, dbName, tblName, "p2 = \"p21\"", 2); + checkFilter(client, dbName, tblName, "p2 = \"p23\"", 1); + checkFilter(client, dbName, tblName, "p1 = \"p11\" and p2=\"p22\"", 1); + checkFilter(client, dbName, tblName, "p1 = \"p11\" or p2=\"p23\"", 3); + checkFilter(client, dbName, tblName, "p1 = \"p11\" or p1=\"p12\"", 4); + + checkFilter(client, dbName, tblName, + "p1 = \"p11\" or (p1=\"p12\" and p2=\"p21\")", 3); + checkFilter(client, dbName, tblName, + "p1 = \"p11\" or (p1=\"p12\" and p2=\"p21\") Or " + + "(p1=\"p13\" aNd p2=\"p24\")", 4); + + checkFilter(client, dbName, tblName, "p1 > \"p12\"", 2); + checkFilter(client, dbName, tblName, "p1 >= \"p12\"", 4); + checkFilter(client, dbName, tblName, "p1 < \"p12\"", 2); + checkFilter(client, dbName, tblName, "p1 <= \"p12\"", 4); + checkFilter(client, dbName, tblName, "p1 <> \"p12\"", 4); + checkFilter(client, dbName, tblName, "p1 like \"p1.*\"", 6); + checkFilter(client, dbName, tblName, "p2 like \"p.*3\"", 1); + + //Test for setting the maximum partition count + List partitions = client.listPartitionsByFilter(dbName, + tblName, "p1 >= \"p12\"", (short) 2); + assertEquals("User specified row limit for partitions", + 2, partitions.size()); + + //Negative tests + MetaException me = null; + try { + client.listPartitionsByFilter(dbName, + tblName, "p3 >= \"p12\"", (short) -1); + } catch(MetaException e) { + me = e; + } + assertNotNull(me); + assertTrue("Filter on int partition key", me.getMessage().contains( + "Filtering is supported only on partition keys of type string")); + + me = null; + try { + client.listPartitionsByFilter(dbName, + tblName, "c1 >= \"p12\"", (short) -1); + } catch(MetaException e) { + me = e; + } + assertNotNull(me); + assertTrue("Filter on invalid key", me.getMessage().contains( + " is not a partitioning key for the table")); + + me = null; + try { + client.listPartitionsByFilter(dbName, + tblName, "c1 >= ", (short) -1); + } catch(MetaException e) { + me = e; + } + assertNotNull(me); + assertTrue("Invalid filter string", me.getMessage().contains( + "Error parsing partition filter")); + } + + private void checkFilter(HiveMetaStoreClient client, String dbName, + String tblName, String filter, int expectedCount) + throws MetaException, TException { + List partitions = client.listPartitionsByFilter(dbName, + tblName, filter, (short) -1); + + assertEquals("Partition count expected for filter " + filter, + expectedCount, partitions.size()); + } + + private void add_partition(HiveMetaStoreClient client, Table table, + List vals, String location) throws InvalidObjectException, + AlreadyExistsException, MetaException, TException { + + Partition part = new Partition(); + part.setDbName(table.getDbName()); + part.setTableName(table.getTableName()); + part.setValues(vals); + part.setParameters(new HashMap()); + part.setSd(table.getSd()); + part.getSd().setSerdeInfo(table.getSd().getSerdeInfo()); + part.getSd().setLocation(table.getSd().getLocation() + location); + + client.add_partition(part); + } } Index: metastore/src/model/package.jdo =================================================================== --- metastore/src/model/package.jdo (revision 991274) +++ metastore/src/model/package.jdo (working copy) @@ -128,10 +128,10 @@ - + - + Index: metastore/src/java/org/apache/hadoop/hive/metastore/RawStore.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/RawStore.java (revision 991274) +++ metastore/src/java/org/apache/hadoop/hive/metastore/RawStore.java (working copy) @@ -122,4 +122,8 @@ public abstract List listIndexNames(String dbName, String origTableName, short max) throws MetaException; + public abstract List getPartitionsByFilter( + String dbName, String tblName, String filter, short maxParts) + throws MetaException; + } Index: metastore/src/java/org/apache/hadoop/hive/metastore/parser/ExpressionTree.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/parser/ExpressionTree.java (revision 0) +++ metastore/src/java/org/apache/hadoop/hive/metastore/parser/ExpressionTree.java (revision 0) @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.metastore.parser; + +import java.util.Map; +import java.util.Stack; + +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.hadoop.hive.serde.Constants; + +/** + * The Class representing the filter as a binary tree. The tree has TreeNode's + * at intermediate level and the leaf level nodes are of type LeafNode. + */ +public class ExpressionTree { + + public enum LogicalOperator { + AND, + OR + } + + public enum Operator { + EQUALS ("=", "=="), + GREATERTHAN (">"), + LESSTHAN ("<"), + LESSTHANOREQUALTO ("<="), + GREATERTHANOREQUALTO (">="), + LIKE ("LIKE", "matches"), + NOTEQUALS ("<>", "!="); + + private final String op; + private final String jdoOp; + + // private constructor + private Operator (String op){ + this.op = op; + this.jdoOp = op; + } + + private Operator (String op, String jdoOp){ + this.op = op; + this.jdoOp = jdoOp; + } + + public String getOp() { + return op; + } + + public String getJdoOp() { + return jdoOp; + } + + public static Operator fromString (String inputOperator) throws Exception{ + for(Operator op : Operator.values()) { + if( op.getOp().equals(inputOperator) ) { + return op; + } + } + + throw new Exception("Invalid value " + inputOperator + + " for " + Operator.class.getSimpleName()); + } + } + + + /** + * The Class representing a Node in the ExpressionTree. + */ + public static class TreeNode { + public TreeNode lhs; + public LogicalOperator andOr; + public TreeNode rhs; + + public String generateJDOFilter(Table table, Map params) + throws MetaException { + StringBuffer filterBuffer = new StringBuffer(); + + if ( lhs != null) { + filterBuffer.append(lhs.generateJDOFilter(table, params)); + + if (rhs != null) { + if( andOr == LogicalOperator.AND ) { + filterBuffer.append(" && "); + } else { + filterBuffer.append(" || "); + } + + filterBuffer.append(rhs.generateJDOFilter(table, params)); + } + } + + return filterBuffer.toString(); + } + + } + + /** + * The Class representing the leaf level nodes in the ExpressionTree. + */ + public static class LeafNode extends TreeNode { + public String keyName; + public Operator operator; + public String value; + public boolean isReverseOrder = false; + private static final String PARAM_PREFIX = "hive_filter_param_"; + + @Override + public String generateJDOFilter(Table table, Map params) + throws MetaException { + int partitionIndex; + for(partitionIndex = 0; + partitionIndex < table.getPartitionKeys().size(); + partitionIndex++ ) { + if( table.getPartitionKeys().get(partitionIndex).getName(). + equalsIgnoreCase(keyName)) { + break; + } + } + + if( partitionIndex == table.getPartitionKeys().size() ) { + throw new MetaException("Specified key <" + keyName + + "> is not a partitioning key for the table"); + } + + if( ! table.getPartitionKeys().get(partitionIndex). + getType().equals(Constants.STRING_TYPE_NAME) ) { + throw new MetaException + ("Filtering is supported only on partition keys of type string"); + } + + String paramName = PARAM_PREFIX + params.size(); + params.put(paramName, value); + String filter; + + //Handle "a > 10" and "10 > a" appropriately + if (isReverseOrder){ + //For LIKE, the value should be on the RHS + if( operator == Operator.LIKE ) { + throw new MetaException( + "Value should be on the RHS for LIKE operator : " + + "Key <" + keyName + ">"); + } + + filter = paramName + + " " + operator.getJdoOp() + " " + + " this.values.get(" + partitionIndex + ")"; + } else { + if( operator == Operator.LIKE ) { + //generate this.values.get(i).matches("abc%") + filter = " this.values.get(" + partitionIndex + ")." + + operator.getJdoOp() + "(" + paramName + ") "; + } else { + filter = " this.values.get(" + partitionIndex + ") " + + operator.getJdoOp() + " " + paramName; + } + } + return filter; + } + } + + /** + * The root node for the tree. + */ + private TreeNode root = null; + + /** + * The node stack used to keep track of the tree nodes during parsing. + */ + private final Stack nodeStack = new Stack(); + + /** + * Adds a intermediate node of either type(AND/OR). Pops last two nodes from + * the stack and sets them as children of the new node and pushes itself + * onto the stack. + * @param andOr the operator type + */ + public void addIntermediateNode(LogicalOperator andOr) { + TreeNode newNode = new TreeNode(); + newNode.rhs = nodeStack.pop(); + newNode.lhs = nodeStack.pop(); + newNode.andOr = andOr; + nodeStack.push(newNode); + root = newNode; + } + + /** + * Adds a leaf node, pushes the new node onto the stack. + * @param newNode the new node + */ + public void addLeafNode(LeafNode newNode) { + if( root == null ) { + root = newNode; + } + nodeStack.push(newNode); + } + + /** Generate the JDOQL filter for the given expression tree + * @param table the table being queried + * @param params the input map which is updated with the + * the parameterized values. Keys are the parameter names and values + * are the parameter values + * @return the string representation of the expression tree + * @throws MetaException + */ + public String generateJDOFilter(Table table, + Map params) throws MetaException { + if( root == null ) { + return ""; + } + + return root.generateJDOFilter(table, params); + } +} Index: metastore/src/java/org/apache/hadoop/hive/metastore/parser/filter_parser.jj =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/parser/filter_parser.jj (revision 0) +++ metastore/src/java/org/apache/hadoop/hive/metastore/parser/filter_parser.jj (revision 0) @@ -0,0 +1,197 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* Parser for metastore partition filter */ +options +{ + STATIC = false ; + IGNORE_CASE = true; +} + +PARSER_BEGIN(FilterParser) +package org.apache.hadoop.hive.metastore.parser; + +import java.io.*; +import java.util.*; +import java.io.PrintStream; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree.LeafNode; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree.Operator; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree.LogicalOperator; + +public class FilterParser +{ + public static void main( String[] args ) throws ParseException, TokenMgrError { + FilterParser parser = new FilterParser(System.in); + parser.Start(); + } + + public static String TrimQuotes( String input ) { + if( input.length() > 1 ) { + if( (input.charAt(0) == '"' && input.charAt(input.length() - 1) == '"') || (input.charAt(0) == '\'' && input.charAt(input.length() - 1) =='\'')) { + return input.substring(1, input.length() -1 ); + } + } + return input; + } +} +PARSER_END(FilterParser) + +SKIP : { " " } +SKIP : { "\t" } +SKIP : { "\n" | "\r" | "\r\n" } + +TOKEN: { < AND : "AND" > } +TOKEN: { < EQUALS: "=" > } +TOKEN: { < CLOSEPAR: (")") >} +TOKEN: { < GE: ">=" > } +TOKEN: { < GT: ">" > } +TOKEN: { < LE: "<=" > } +TOKEN: { < LIKE: "LIKE" > } +TOKEN: { < LT: "<" > } +TOKEN: { < NOTEQUALS : "<>" > } +TOKEN: { < OPENPAR: ("(") >} +TOKEN: { < OR: "OR" >} +TOKEN: { < QUOTE: ("\"")>} +TOKEN: { < SINGLEQUOTE: ("\'")>} + +TOKEN: { < IDENTIFIER : (["a"-"z","A"-"Z"] | ["0"-"9"] | ["_"])+ > } +TOKEN: { < LITERAL : (( (~["\n","\r","\""])* ) | ( (~["\n","\r","\'"])* )) > } + + +// The grammar for the filter +ExpressionTree Start() throws ParseException : { + ExpressionTree tree = new ExpressionTree(); +} +{ + ( + try { + FilterExpression(tree) + } catch(Exception e) { + if( e instanceof ParseException ) { + throw (ParseException) e; + } else { + throw new ParseException("Error parsing filter expression : " + + e.toString()); + } + } catch(Error e) { + throw new ParseException("Error parsing filter expression : " + + e.toString()); + } + ) + { + return tree; + } +} + +void FilterExpression(ExpressionTree tree) throws Exception : { +} +{ + ( + FilterOrExpression(tree) + ) +} + +//The OR expression grammar +void FilterOrExpression(ExpressionTree tree) throws Exception : { +} +{ + ( + FilterAndExpression(tree) + ( + + FilterAndExpression(tree) + { + tree.addIntermediateNode(LogicalOperator.OR); + } + )* + ) +} + +//The AND expression grammar +void FilterAndExpression(ExpressionTree tree) throws Exception : { +} +{ + ( + FilterCondition(tree) + ( + + FilterCondition(tree) + { + tree.addIntermediateNode(LogicalOperator.AND); + } + )* + ) +} + +//The condition grammar, condition being a expression with brackets +//or a filter operation +void FilterCondition(ExpressionTree tree) throws Exception : { +} +{ + ( + LOOKAHEAD( FilterExpression(tree) ) + ( FilterExpression(tree) ) + | + ( FilterOperation(tree) ) + ) +} + + +void FilterOperation(ExpressionTree tree) throws Exception : +{ + Token key = null, stringValue = null; + Operator operator = null; + boolean isReverseOrder = false; +} +{ + ( + ( key = operator = FilterOperator() stringValue = ) + | + ( stringValue = operator = FilterOperator() key = + { + isReverseOrder = true; + } + ) + ) + { + LeafNode node = new LeafNode(); + node.keyName = key.image; + node.value = TrimQuotes(stringValue.image); + node.operator = operator; + node.isReverseOrder = isReverseOrder; + + tree.addLeafNode(node); + } +} + +Operator FilterOperator() throws Exception : +{ + Token t = null; +} +{ + ( + ( (t = ) | (t = ) | (t = ) | (t = ) | (t = ) | + (t = ) | (t = ) ) + { + return Operator.fromString(t.image.toUpperCase()); + } + ) +} + Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java (revision 991274) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java (working copy) @@ -517,6 +517,25 @@ } /** + * Get list of partitions matching specified filter + * @param db_name the database name + * @param tbl_name the table name + * @param filter the filter string, + * for example "part1 = \"p1_abc\" and part2 <= "\p2_test\"". Filtering can + * be done only on string partition keys. + * @param max_parts the maximum number of partitions to return, + * all partitions are returned if -1 is passed + * @return list of partitions + * @throws MetaException + * @throws TException + */ + public List listPartitionsByFilter(String db_name, String tbl_name, + String filter, short max_parts) throws MetaException, TException { + return deepCopyPartitions( + client.get_partitions_by_filter(db_name, tbl_name, filter, max_parts)); + } + + /** * @param name * @return the database * @throws NoSuchObjectException Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (revision 991274) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (working copy) @@ -2074,6 +2074,30 @@ return ret; } + @Override + public List get_partitions_by_filter(final String dbName, + final String tblName, final String filter, final short maxParts) + throws MetaException, TException { + incrementCounter("get_partitions_by_filter"); + logStartTableFunction("get_partitions_by_filter", dbName, tblName); + + List ret = null; + try { + ret = executeWithRetry(new Command>() { + @Override + List run(RawStore ms) throws Exception { + return ms.getPartitionsByFilter(dbName, tblName, filter, maxParts); + } + }); + } catch (MetaException e) { + throw e; + } catch (Exception e) { + assert(e instanceof RuntimeException); + throw (RuntimeException)e; + } + return ret; + } + } /** Index: metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java (revision 991274) +++ metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java (working copy) @@ -18,8 +18,10 @@ package org.apache.hadoop.hive.metastore; +import java.io.ByteArrayInputStream; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -62,6 +64,9 @@ import org.apache.hadoop.hive.metastore.model.MStorageDescriptor; import org.apache.hadoop.hive.metastore.model.MTable; import org.apache.hadoop.hive.metastore.model.MType; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree; +import org.apache.hadoop.hive.metastore.parser.FilterParser; +import org.apache.hadoop.hive.metastore.parser.ParseException; import org.apache.hadoop.util.StringUtils; /** @@ -944,6 +949,78 @@ return mparts; } + private List listMPartitionsByFilter(String dbName, String tableName, + String filter, short maxParts) throws MetaException { + boolean success = false; + List mparts = null; + try { + openTransaction(); + LOG.debug("Executing listMPartitionsByFilter"); + dbName = dbName.toLowerCase(); + tableName = tableName.toLowerCase(); + + StringBuffer queryBuffer = new StringBuffer( + "table.tableName == t1 && table.database.name == t2"); + + Map params = new HashMap(); + + if( filter != null ) { + ByteArrayInputStream bi = new ByteArrayInputStream(filter.getBytes()); + FilterParser parser = new FilterParser(bi); + + ExpressionTree tree = null; + Table table = convertToTable(getMTable(dbName, tableName)); + try { + tree = parser.Start(); + } catch(ParseException pe) { + throw new MetaException("Error parsing partition filter : " + pe); + } + + String jdoFilter = tree.generateJDOFilter(table, params); + + if( jdoFilter.trim().length() > 0 ) { + queryBuffer.append(" && ( "); + queryBuffer.append(jdoFilter.trim()); + queryBuffer.append(" )"); + } + } + + Query query = pm.newQuery(MPartition.class, + queryBuffer.toString()); + + if( maxParts >= 0 ) { + //User specified a row limit, set it on the Query + query.setRange(0, maxParts); + } + + //Create the parameter declaration string + StringBuffer paramDecl = new StringBuffer( + "java.lang.String t1, java.lang.String t2"); + for(String key : params.keySet() ) { + paramDecl.append(", java.lang.String " + key); + } + + LOG.debug("Filter specified is " + filter + "," + + " JDOQL filter is " + queryBuffer.toString()); + + params.put("t1", tableName.trim()); + params.put("t2", dbName.trim()); + + query.declareParameters(paramDecl.toString()); + mparts = (List) query.executeWithMap(params); + + LOG.debug("Done executing query for listMPartitionsByFilter"); + pm.retrieveAll(mparts); + success = commitTransaction(); + LOG.debug("Done retrieving all objects for listMPartitionsByFilter"); + } finally { + if (!success) { + rollbackTransaction(); + } + } + return mparts; + } + public void alterTable(String dbname, String name, Table newTable) throws InvalidObjectException, MetaException { boolean success = false; @@ -1217,4 +1294,14 @@ } return pns; } + + @Override + public List getPartitionsByFilter(String dbName, String tblName, + String filter, short maxParts) throws MetaException { + openTransaction(); + List parts = convertToParts(listMPartitionsByFilter(dbName, + tblName, filter, maxParts)); + commitTransaction(); + return parts; + } } Index: metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/FilterParserConstants.java =================================================================== --- metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/FilterParserConstants.java (revision 0) +++ metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/FilterParserConstants.java (revision 0) @@ -0,0 +1,72 @@ +/* Generated By:JavaCC: Do not edit this line. FilterParserConstants.java */ +package org.apache.hadoop.hive.metastore.parser; + + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ +public interface FilterParserConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int AND = 6; + /** RegularExpression Id. */ + int EQUALS = 7; + /** RegularExpression Id. */ + int CLOSEPAR = 8; + /** RegularExpression Id. */ + int GE = 9; + /** RegularExpression Id. */ + int GT = 10; + /** RegularExpression Id. */ + int LE = 11; + /** RegularExpression Id. */ + int LIKE = 12; + /** RegularExpression Id. */ + int LT = 13; + /** RegularExpression Id. */ + int NOTEQUALS = 14; + /** RegularExpression Id. */ + int OPENPAR = 15; + /** RegularExpression Id. */ + int OR = 16; + /** RegularExpression Id. */ + int QUOTE = 17; + /** RegularExpression Id. */ + int SINGLEQUOTE = 18; + /** RegularExpression Id. */ + int IDENTIFIER = 19; + /** RegularExpression Id. */ + int LITERAL = 20; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "\"\\r\\n\"", + "\"AND\"", + "\"=\"", + "\")\"", + "\">=\"", + "\">\"", + "\"<=\"", + "\"LIKE\"", + "\"<\"", + "\"<>\"", + "\"(\"", + "\"OR\"", + "\"\\\"\"", + "\"\\\'\"", + "", + "", + }; + +} Index: metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/TokenMgrError.java =================================================================== --- metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/TokenMgrError.java (revision 0) +++ metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/TokenMgrError.java (revision 0) @@ -0,0 +1,147 @@ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 4.1 */ +/* JavaCCOptions: */ +package org.apache.hadoop.hive.metastore.parser; + +/** Token Manager Error. */ +public class TokenMgrError extends Error +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + + /** No arg constructor. */ + public TokenMgrError() { + } + + /** Constructor with message and reason. */ + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* JavaCC - OriginalChecksum=21ee80900c058cebb49e694ba2d01b7c (do not edit this line) */ Index: metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/Token.java =================================================================== --- metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/Token.java (revision 0) +++ metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/Token.java (revision 0) @@ -0,0 +1,131 @@ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 4.1 */ +/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +package org.apache.hadoop.hive.metastore.parser; + +/** + * Describes the input token stream. + */ + +public class Token implements java.io.Serializable { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(int kind) + { + this(kind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(int kind, String image) + { + this.kind = kind; + this.image = image; + } + + /** + * Returns the image. + */ + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* JavaCC - OriginalChecksum=311e0ebb756ba27710975bd835abe5de (do not edit this line) */ Index: metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/FilterParser.java =================================================================== --- metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/FilterParser.java (revision 0) +++ metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/FilterParser.java (revision 0) @@ -0,0 +1,572 @@ +/* Generated By:JavaCC: Do not edit this line. FilterParser.java */ +package org.apache.hadoop.hive.metastore.parser; + +import java.io.*; +import java.util.*; +import java.io.PrintStream; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree.LeafNode; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree.Operator; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree.LogicalOperator; + +public class FilterParser implements FilterParserConstants { + public static void main( String[] args ) throws ParseException, TokenMgrError { + FilterParser parser = new FilterParser(System.in); + parser.Start(); + } + + public static String TrimQuotes( String input ) { + if( input.length() > 1 ) { + if( (input.charAt(0) == '"' && input.charAt(input.length() - 1) == '"') || (input.charAt(0) == '\u005c'' && input.charAt(input.length() - 1) =='\u005c'')) { + return input.substring(1, input.length() -1 ); + } + } + return input; + } + +// The grammar for the filter + final public ExpressionTree Start() throws ParseException, ParseException { + ExpressionTree tree = new ExpressionTree(); + try { + FilterExpression(tree); + } catch (Exception e) { + if( e instanceof ParseException ) { + {if (true) throw (ParseException) e;} + } else { + {if (true) throw new ParseException("Error parsing filter expression : " + + e.toString());} + } + } catch (Error e) { + {if (true) throw new ParseException("Error parsing filter expression : " + + e.toString());} + } + {if (true) return tree;} + throw new Error("Missing return statement in function"); + } + + final public void FilterExpression(ExpressionTree tree) throws ParseException, Exception { + FilterOrExpression(tree); + } + +//The OR expression grammar + final public void FilterOrExpression(ExpressionTree tree) throws ParseException, Exception { + FilterAndExpression(tree); + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case OR: + ; + break; + default: + jj_la1[0] = jj_gen; + break label_1; + } + jj_consume_token(OR); + FilterAndExpression(tree); + tree.addIntermediateNode(LogicalOperator.OR); + } + } + +//The AND expression grammar + final public void FilterAndExpression(ExpressionTree tree) throws ParseException, Exception { + FilterCondition(tree); + label_2: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case AND: + ; + break; + default: + jj_la1[1] = jj_gen; + break label_2; + } + jj_consume_token(AND); + FilterCondition(tree); + tree.addIntermediateNode(LogicalOperator.AND); + } + } + +//The condition grammar, condition being a expression with brackets +//or a filter operation + final public void FilterCondition(ExpressionTree tree) throws ParseException, Exception { + if (jj_2_1(2147483647)) { + jj_consume_token(OPENPAR); + FilterExpression(tree); + jj_consume_token(CLOSEPAR); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENTIFIER: + case LITERAL: + FilterOperation(tree); + break; + default: + jj_la1[2] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + + final public void FilterOperation(ExpressionTree tree) throws ParseException, Exception { + Token key = null, stringValue = null; + Operator operator = null; + boolean isReverseOrder = false; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENTIFIER: + key = jj_consume_token(IDENTIFIER); + operator = FilterOperator(); + stringValue = jj_consume_token(LITERAL); + break; + case LITERAL: + stringValue = jj_consume_token(LITERAL); + operator = FilterOperator(); + key = jj_consume_token(IDENTIFIER); + isReverseOrder = true; + break; + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + LeafNode node = new LeafNode(); + node.keyName = key.image; + node.value = TrimQuotes(stringValue.image); + node.operator = operator; + node.isReverseOrder = isReverseOrder; + + tree.addLeafNode(node); + } + + final public Operator FilterOperator() throws ParseException, Exception { + Token t = null; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LE: + t = jj_consume_token(LE); + break; + case LT: + t = jj_consume_token(LT); + break; + case GE: + t = jj_consume_token(GE); + break; + case GT: + t = jj_consume_token(GT); + break; + case LIKE: + t = jj_consume_token(LIKE); + break; + case EQUALS: + t = jj_consume_token(EQUALS); + break; + case NOTEQUALS: + t = jj_consume_token(NOTEQUALS); + break; + default: + jj_la1[4] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + {if (true) return Operator.fromString(t.image.toUpperCase());} + throw new Error("Missing return statement in function"); + } + + private boolean jj_2_1(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_1(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + private boolean jj_3R_5() { + if (jj_3R_7()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_8()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_9() { + if (jj_scan_token(OPENPAR)) return true; + if (jj_3R_3()) return true; + if (jj_scan_token(CLOSEPAR)) return true; + return false; + } + + private boolean jj_3R_3() { + if (jj_3R_4()) return true; + return false; + } + + private boolean jj_3R_6() { + if (jj_scan_token(OR)) return true; + if (jj_3R_5()) return true; + return false; + } + + private boolean jj_3R_13() { + if (jj_scan_token(LITERAL)) return true; + if (jj_3R_14()) return true; + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + private boolean jj_3R_7() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_9()) { + jj_scanpos = xsp; + if (jj_3R_10()) return true; + } + return false; + } + + private boolean jj_3R_12() { + if (jj_scan_token(IDENTIFIER)) return true; + if (jj_3R_14()) return true; + if (jj_scan_token(LITERAL)) return true; + return false; + } + + private boolean jj_3R_14() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(11)) { + jj_scanpos = xsp; + if (jj_scan_token(13)) { + jj_scanpos = xsp; + if (jj_scan_token(9)) { + jj_scanpos = xsp; + if (jj_scan_token(10)) { + jj_scanpos = xsp; + if (jj_scan_token(12)) { + jj_scanpos = xsp; + if (jj_scan_token(7)) { + jj_scanpos = xsp; + if (jj_scan_token(14)) return true; + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_8() { + if (jj_scan_token(AND)) return true; + if (jj_3R_7()) return true; + return false; + } + + private boolean jj_3R_11() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_12()) { + jj_scanpos = xsp; + if (jj_3R_13()) return true; + } + return false; + } + + private boolean jj_3_1() { + if (jj_scan_token(OPENPAR)) return true; + if (jj_3R_3()) return true; + if (jj_scan_token(CLOSEPAR)) return true; + return false; + } + + private boolean jj_3R_4() { + if (jj_3R_5()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_6()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_10() { + if (jj_3R_11()) return true; + return false; + } + + /** Generated Token Manager. */ + public FilterParserTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + private int jj_gen; + final private int[] jj_la1 = new int[5]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x10000,0x40,0x180000,0x180000,0x7e80,}; + } + final private JJCalls[] jj_2_rtns = new JJCalls[1]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + /** Constructor with InputStream. */ + public FilterParser(java.io.InputStream stream) { + this(stream, null); + } + /** Constructor with InputStream and supplied encoding */ + public FilterParser(java.io.InputStream stream, String encoding) { + try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new FilterParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream, String encoding) { + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor. */ + public FilterParser(java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new FilterParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader stream) { + jj_input_stream.ReInit(stream, 1, 1); + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor with generated Token Manager. */ + public FilterParser(FilterParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(FilterParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + static private final class LookaheadSuccess extends java.lang.Error { } + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + +/** Get the next Token. */ + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + +/** Get the specific Token. */ + final public Token getToken(int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + private int jj_ntk() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) return; + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { + int[] oldentry = (int[])(it.next()); + if (oldentry.length == jj_expentry.length) { + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + continue jj_entries_loop; + } + } + jj_expentries.add(jj_expentry); + break jj_entries_loop; + } + } + if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + + /** Generate ParseException. */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[21]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 5; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1< jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} Index: metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/SimpleCharStream.java =================================================================== --- metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/SimpleCharStream.java (revision 0) +++ metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/SimpleCharStream.java (revision 0) @@ -0,0 +1,469 @@ +/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.1 */ +/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +package org.apache.hadoop.hive.metastore.parser; + +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public class SimpleCharStream +{ +/** Whether parser is static. */ + public static final boolean staticFlag = false; + int bufsize; + int available; + int tokenBegin; +/** Position in buffer. */ + public int bufpos = -1; + protected int bufline[]; + protected int bufcolumn[]; + + protected int column = 0; + protected int line = 1; + + protected boolean prevCharIsCR = false; + protected boolean prevCharIsLF = false; + + protected java.io.Reader inputStream; + + protected char[] buffer; + protected int maxNextCharInd = 0; + protected int inBuf = 0; + protected int tabSize = 8; + + protected void setTabSize(int i) { tabSize = i; } + protected int getTabSize(int i) { return tabSize; } + + + protected void ExpandBuff(boolean wrapAround) + { + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; + + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos += (bufsize - tokenBegin)); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos -= tokenBegin); + } + } + catch (Throwable t) + { + throw new Error(t.getMessage()); + } + + + bufsize += 2048; + available = bufsize; + tokenBegin = 0; + } + + protected void FillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + { + if (available == bufsize) + { + if (tokenBegin > 2048) + { + bufpos = maxNextCharInd = 0; + available = tokenBegin; + } + else if (tokenBegin < 0) + bufpos = maxNextCharInd = 0; + else + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } + + int i; + try { + if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + --bufpos; + backup(0); + if (tokenBegin == -1) + tokenBegin = bufpos; + throw e; + } + } + +/** Start. */ + public char BeginToken() throws java.io.IOException + { + tokenBegin = -1; + char c = readChar(); + tokenBegin = bufpos; + + return c; + } + + protected void UpdateLineColumn(char c) + { + column++; + + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else + line += (column = 1); + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + +/** Read a character. */ + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + return buffer[bufpos]; + } + + if (++bufpos >= maxNextCharInd) + FillBuff(); + + char c = buffer[bufpos]; + + UpdateLineColumn(c); + return c; + } + + /** + * @deprecated + * @see #getEndColumn + */ + + public int getColumn() { + return bufcolumn[bufpos]; + } + + /** + * @deprecated + * @see #getEndLine + */ + + public int getLine() { + return bufline[bufpos]; + } + + /** Get token end column number. */ + public int getEndColumn() { + return bufcolumn[bufpos]; + } + + /** Get token end line number. */ + public int getEndLine() { + return bufline[bufpos]; + } + + /** Get token beginning column number. */ + public int getBeginColumn() { + return bufcolumn[tokenBegin]; + } + + /** Get token beginning line number. */ + public int getBeginLine() { + return bufline[tokenBegin]; + } + +/** Backup a number of characters. */ + public void backup(int amount) { + + inBuf += amount; + if ((bufpos -= amount) < 0) + bufpos += bufsize; + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.Reader dstream) + { + this(dstream, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream, int startline, + int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + if (buffer == null || buffersize != buffer.length) + { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } + prevCharIsLF = prevCharIsCR = false; + tokenBegin = inBuf = maxNextCharInd = 0; + bufpos = -1; + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader dstream) + { + ReInit(dstream, 1, 1, 4096); + } + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, 4096); + } + + /** Constructor. */ + public SimpleCharStream(java.io.InputStream dstream) + { + this(dstream, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, 1, 1, 4096); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream) + { + ReInit(dstream, 1, 1, 4096); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, startline, startcolumn, 4096); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + /** Get token literal value. */ + public String GetImage() + { + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); + } + + /** Get the suffix. */ + public char[] GetSuffix(int len) + { + char[] ret = new char[len]; + + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } + + return ret; + } + + /** Reset buffer when finished. */ + public void Done() + { + buffer = null; + bufline = null; + bufcolumn = null; + } + + /** + * Method to adjust line and column numbers for the start of a token. + */ + public void adjustBeginLineColumn(int newLine, int newCol) + { + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } + + line = bufline[j]; + column = bufcolumn[j]; + } + +} +/* JavaCC - OriginalChecksum=ea47155d69dac9ab94db969b067d33e6 (do not edit this line) */ Index: metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/ParseException.java =================================================================== --- metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/ParseException.java (revision 0) +++ metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/ParseException.java (revision 0) @@ -0,0 +1,187 @@ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 4.1 */ +/* JavaCCOptions:KEEP_LINE_COL=null */ +package org.apache.hadoop.hive.metastore.parser; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String initialise(Token currentToken, + int[][] expectedTokenSequences, + String[] tokenImage) { + String eol = System.getProperty("line.separator", "\n"); + StringBuffer expected = new StringBuffer(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) { + maxSize = expectedTokenSequences[i].length; + } + for (int j = 0; j < expectedTokenSequences[i].length; j++) { + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + } + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { + expected.append("..."); + } + expected.append(eol).append(" "); + } + String retval = "Encountered \""; + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + if (i != 0) retval += " "; + if (tok.kind == 0) { + retval += tokenImage[0]; + break; + } + retval += " " + tokenImage[tok.kind]; + retval += " \""; + retval += add_escapes(tok.image); + retval += " \""; + tok = tok.next; + } + retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; + retval += "." + eol; + if (expectedTokenSequences.length == 1) { + retval += "Was expecting:" + eol + " "; + } else { + retval += "Was expecting one of:" + eol + " "; + } + retval += expected.toString(); + return retval; + } + + /** + * The end of line string for this machine. + */ + protected String eol = System.getProperty("line.separator", "\n"); + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + +} +/* JavaCC - OriginalChecksum=f922eb14f0ec90a2065020766eed5eac (do not edit this line) */ Index: metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/FilterParserTokenManager.java =================================================================== --- metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/FilterParserTokenManager.java (revision 0) +++ metastore/src/gen-java/org/apache/hadoop/hive/metastore/parser/FilterParserTokenManager.java (revision 0) @@ -0,0 +1,523 @@ +/* Generated By:JavaCC: Do not edit this line. FilterParserTokenManager.java */ +package org.apache.hadoop.hive.metastore.parser; +import java.io.*; +import java.util.*; +import java.io.PrintStream; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree.LeafNode; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree.Operator; +import org.apache.hadoop.hive.metastore.parser.ExpressionTree.LogicalOperator; + +/** Token Manager. */ +public class FilterParserTokenManager implements FilterParserConstants +{ + + /** Debug output. */ + public java.io.PrintStream debugStream = System.out; + /** Set debug output. */ + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0) +{ + switch (pos) + { + case 0: + if ((active0 & 0x40000L) != 0L) + return 7; + if ((active0 & 0x11040L) != 0L) + { + jjmatchedKind = 19; + return 0; + } + if ((active0 & 0x20000L) != 0L) + return 8; + return -1; + case 1: + if ((active0 & 0x10000L) != 0L) + return 0; + if ((active0 & 0x1040L) != 0L) + { + jjmatchedKind = 19; + jjmatchedPos = 1; + return 0; + } + return -1; + case 2: + if ((active0 & 0x40L) != 0L) + return 0; + if ((active0 & 0x1000L) != 0L) + { + jjmatchedKind = 19; + jjmatchedPos = 2; + return 0; + } + return -1; + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0) +{ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0() +{ + switch(curChar) + { + case 13: + jjmatchedKind = 4; + return jjMoveStringLiteralDfa1_0(0x20L); + case 34: + return jjStartNfaWithStates_0(0, 17, 8); + case 39: + return jjStartNfaWithStates_0(0, 18, 7); + case 40: + return jjStopAtPos(0, 15); + case 41: + return jjStopAtPos(0, 8); + case 60: + jjmatchedKind = 13; + return jjMoveStringLiteralDfa1_0(0x4800L); + case 61: + return jjStopAtPos(0, 7); + case 62: + jjmatchedKind = 10; + return jjMoveStringLiteralDfa1_0(0x200L); + case 65: + case 97: + return jjMoveStringLiteralDfa1_0(0x40L); + case 76: + case 108: + return jjMoveStringLiteralDfa1_0(0x1000L); + case 79: + case 111: + return jjMoveStringLiteralDfa1_0(0x10000L); + default : + return jjMoveNfa_0(1, 0); + } +} +private int jjMoveStringLiteralDfa1_0(long active0) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0); + return 1; + } + switch(curChar) + { + case 10: + if ((active0 & 0x20L) != 0L) + return jjStopAtPos(1, 5); + break; + case 61: + if ((active0 & 0x200L) != 0L) + return jjStopAtPos(1, 9); + else if ((active0 & 0x800L) != 0L) + return jjStopAtPos(1, 11); + break; + case 62: + if ((active0 & 0x4000L) != 0L) + return jjStopAtPos(1, 14); + break; + case 73: + case 105: + return jjMoveStringLiteralDfa2_0(active0, 0x1000L); + case 78: + case 110: + return jjMoveStringLiteralDfa2_0(active0, 0x40L); + case 82: + case 114: + if ((active0 & 0x10000L) != 0L) + return jjStartNfaWithStates_0(1, 16, 0); + break; + default : + break; + } + return jjStartNfa_0(0, active0); +} +private int jjMoveStringLiteralDfa2_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(0, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0); + return 2; + } + switch(curChar) + { + case 68: + case 100: + if ((active0 & 0x40L) != 0L) + return jjStartNfaWithStates_0(2, 6, 0); + break; + case 75: + case 107: + return jjMoveStringLiteralDfa3_0(active0, 0x1000L); + default : + break; + } + return jjStartNfa_0(1, active0); +} +private int jjMoveStringLiteralDfa3_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(1, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0); + return 3; + } + switch(curChar) + { + case 69: + case 101: + if ((active0 & 0x1000L) != 0L) + return jjStartNfaWithStates_0(3, 12, 0); + break; + default : + break; + } + return jjStartNfa_0(2, active0); +} +private int jjStartNfaWithStates_0(int pos, int kind, int state) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return pos + 1; } + return jjMoveNfa_0(state, pos + 1); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 7; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 8: + if ((0xfffffffbffffdbffL & l) != 0L) + jjCheckNAddTwoStates(2, 3); + else if (curChar == 34) + { + if (kind > 20) + kind = 20; + } + break; + case 1: + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 19) + kind = 19; + jjCheckNAdd(0); + } + else if (curChar == 39) + jjCheckNAddTwoStates(5, 6); + else if (curChar == 34) + jjCheckNAddTwoStates(2, 3); + break; + case 7: + if ((0xffffff7fffffdbffL & l) != 0L) + jjCheckNAddTwoStates(5, 6); + else if (curChar == 39) + { + if (kind > 20) + kind = 20; + } + break; + case 0: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 19) + kind = 19; + jjCheckNAdd(0); + break; + case 2: + if ((0xfffffffbffffdbffL & l) != 0L) + jjCheckNAddTwoStates(2, 3); + break; + case 3: + if (curChar == 34 && kind > 20) + kind = 20; + break; + case 4: + if (curChar == 39) + jjCheckNAddTwoStates(5, 6); + break; + case 5: + if ((0xffffff7fffffdbffL & l) != 0L) + jjCheckNAddTwoStates(5, 6); + break; + case 6: + if (curChar == 39 && kind > 20) + kind = 20; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 8: + case 2: + jjCheckNAddTwoStates(2, 3); + break; + case 1: + case 0: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 19) + kind = 19; + jjCheckNAdd(0); + break; + case 7: + case 5: + jjCheckNAddTwoStates(5, 6); + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 8: + case 2: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(2, 3); + break; + case 7: + case 5: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(5, 6); + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 7 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +static final int[] jjnextStates = { +}; + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, null, null, "\75", "\51", "\76\75", "\76", +"\74\75", null, "\74", "\74\76", "\50", null, "\42", "\47", null, null, }; + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; +static final long[] jjtoToken = { + 0x1fffc1L, +}; +static final long[] jjtoSkip = { + 0x3eL, +}; +protected SimpleCharStream input_stream; +private final int[] jjrounds = new int[7]; +private final int[] jjstateSet = new int[14]; +protected char curChar; +/** Constructor. */ +public FilterParserTokenManager(SimpleCharStream stream){ + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + input_stream = stream; +} + +/** Constructor. */ +public FilterParserTokenManager(SimpleCharStream stream, int lexState){ + this(stream); + SwitchTo(lexState); +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream) +{ + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); +} +private void ReInitRounds() +{ + int i; + jjround = 0x80000001; + for (i = 7; i-- > 0;) + jjrounds[i] = 0x80000000; +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream, int lexState) +{ + ReInit(stream); + SwitchTo(lexState); +} + +/** Switch to specified lex state. */ +public void SwitchTo(int lexState) +{ + if (lexState >= 1 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; +} + +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind, curTokenImage); + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + matchedToken = jjFillToken(); + return matchedToken; + } + + try { input_stream.backup(0); + while (curChar <= 32 && (0x100000600L & (1L << curChar)) != 0L) + curChar = input_stream.BeginToken(); + } + catch (java.io.IOException e1) { continue EOFLoop; } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + } + throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); + } +} + +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +} Index: metastore/src/gen-cpp/ThriftHiveMetastore.cpp =================================================================== --- metastore/src/gen-cpp/ThriftHiveMetastore.cpp (revision 991274) +++ metastore/src/gen-cpp/ThriftHiveMetastore.cpp (working copy) @@ -6438,6 +6438,258 @@ return xfer; } +uint32_t ThriftHiveMetastore_get_partitions_by_filter_args::read(apache::thrift::protocol::TProtocol* iprot) { + + uint32_t xfer = 0; + std::string fname; + apache::thrift::protocol::TType ftype; + int16_t fid; + + xfer += iprot->readStructBegin(fname); + + using apache::thrift::protocol::TProtocolException; + + + while (true) + { + xfer += iprot->readFieldBegin(fname, ftype, fid); + if (ftype == apache::thrift::protocol::T_STOP) { + break; + } + switch (fid) + { + case 1: + if (ftype == apache::thrift::protocol::T_STRING) { + xfer += iprot->readString(this->db_name); + this->__isset.db_name = true; + } else { + xfer += iprot->skip(ftype); + } + break; + case 2: + if (ftype == apache::thrift::protocol::T_STRING) { + xfer += iprot->readString(this->tbl_name); + this->__isset.tbl_name = true; + } else { + xfer += iprot->skip(ftype); + } + break; + case 3: + if (ftype == apache::thrift::protocol::T_STRING) { + xfer += iprot->readString(this->filter); + this->__isset.filter = true; + } else { + xfer += iprot->skip(ftype); + } + break; + case 4: + if (ftype == apache::thrift::protocol::T_I16) { + xfer += iprot->readI16(this->max_parts); + this->__isset.max_parts = true; + } else { + xfer += iprot->skip(ftype); + } + break; + default: + xfer += iprot->skip(ftype); + break; + } + xfer += iprot->readFieldEnd(); + } + + xfer += iprot->readStructEnd(); + + return xfer; +} + +uint32_t ThriftHiveMetastore_get_partitions_by_filter_args::write(apache::thrift::protocol::TProtocol* oprot) const { + uint32_t xfer = 0; + xfer += oprot->writeStructBegin("ThriftHiveMetastore_get_partitions_by_filter_args"); + xfer += oprot->writeFieldBegin("db_name", apache::thrift::protocol::T_STRING, 1); + xfer += oprot->writeString(this->db_name); + xfer += oprot->writeFieldEnd(); + xfer += oprot->writeFieldBegin("tbl_name", apache::thrift::protocol::T_STRING, 2); + xfer += oprot->writeString(this->tbl_name); + xfer += oprot->writeFieldEnd(); + xfer += oprot->writeFieldBegin("filter", apache::thrift::protocol::T_STRING, 3); + xfer += oprot->writeString(this->filter); + xfer += oprot->writeFieldEnd(); + xfer += oprot->writeFieldBegin("max_parts", apache::thrift::protocol::T_I16, 4); + xfer += oprot->writeI16(this->max_parts); + xfer += oprot->writeFieldEnd(); + xfer += oprot->writeFieldStop(); + xfer += oprot->writeStructEnd(); + return xfer; +} + +uint32_t ThriftHiveMetastore_get_partitions_by_filter_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { + uint32_t xfer = 0; + xfer += oprot->writeStructBegin("ThriftHiveMetastore_get_partitions_by_filter_pargs"); + xfer += oprot->writeFieldBegin("db_name", apache::thrift::protocol::T_STRING, 1); + xfer += oprot->writeString((*(this->db_name))); + xfer += oprot->writeFieldEnd(); + xfer += oprot->writeFieldBegin("tbl_name", apache::thrift::protocol::T_STRING, 2); + xfer += oprot->writeString((*(this->tbl_name))); + xfer += oprot->writeFieldEnd(); + xfer += oprot->writeFieldBegin("filter", apache::thrift::protocol::T_STRING, 3); + xfer += oprot->writeString((*(this->filter))); + xfer += oprot->writeFieldEnd(); + xfer += oprot->writeFieldBegin("max_parts", apache::thrift::protocol::T_I16, 4); + xfer += oprot->writeI16((*(this->max_parts))); + xfer += oprot->writeFieldEnd(); + xfer += oprot->writeFieldStop(); + xfer += oprot->writeStructEnd(); + return xfer; +} + +uint32_t ThriftHiveMetastore_get_partitions_by_filter_result::read(apache::thrift::protocol::TProtocol* iprot) { + + uint32_t xfer = 0; + std::string fname; + apache::thrift::protocol::TType ftype; + int16_t fid; + + xfer += iprot->readStructBegin(fname); + + using apache::thrift::protocol::TProtocolException; + + + while (true) + { + xfer += iprot->readFieldBegin(fname, ftype, fid); + if (ftype == apache::thrift::protocol::T_STOP) { + break; + } + switch (fid) + { + case 0: + if (ftype == apache::thrift::protocol::T_LIST) { + { + this->success.clear(); + uint32_t _size250; + apache::thrift::protocol::TType _etype253; + iprot->readListBegin(_etype253, _size250); + this->success.resize(_size250); + uint32_t _i254; + for (_i254 = 0; _i254 < _size250; ++_i254) + { + xfer += this->success[_i254].read(iprot); + } + iprot->readListEnd(); + } + this->__isset.success = true; + } else { + xfer += iprot->skip(ftype); + } + break; + case 1: + if (ftype == apache::thrift::protocol::T_STRUCT) { + xfer += this->o1.read(iprot); + this->__isset.o1 = true; + } else { + xfer += iprot->skip(ftype); + } + break; + default: + xfer += iprot->skip(ftype); + break; + } + xfer += iprot->readFieldEnd(); + } + + xfer += iprot->readStructEnd(); + + return xfer; +} + +uint32_t ThriftHiveMetastore_get_partitions_by_filter_result::write(apache::thrift::protocol::TProtocol* oprot) const { + + uint32_t xfer = 0; + + xfer += oprot->writeStructBegin("ThriftHiveMetastore_get_partitions_by_filter_result"); + + if (this->__isset.success) { + xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_LIST, 0); + { + xfer += oprot->writeListBegin(apache::thrift::protocol::T_STRUCT, this->success.size()); + std::vector ::const_iterator _iter255; + for (_iter255 = this->success.begin(); _iter255 != this->success.end(); ++_iter255) + { + xfer += (*_iter255).write(oprot); + } + xfer += oprot->writeListEnd(); + } + xfer += oprot->writeFieldEnd(); + } else if (this->__isset.o1) { + xfer += oprot->writeFieldBegin("o1", apache::thrift::protocol::T_STRUCT, 1); + xfer += this->o1.write(oprot); + xfer += oprot->writeFieldEnd(); + } + xfer += oprot->writeFieldStop(); + xfer += oprot->writeStructEnd(); + return xfer; +} + +uint32_t ThriftHiveMetastore_get_partitions_by_filter_presult::read(apache::thrift::protocol::TProtocol* iprot) { + + uint32_t xfer = 0; + std::string fname; + apache::thrift::protocol::TType ftype; + int16_t fid; + + xfer += iprot->readStructBegin(fname); + + using apache::thrift::protocol::TProtocolException; + + + while (true) + { + xfer += iprot->readFieldBegin(fname, ftype, fid); + if (ftype == apache::thrift::protocol::T_STOP) { + break; + } + switch (fid) + { + case 0: + if (ftype == apache::thrift::protocol::T_LIST) { + { + (*(this->success)).clear(); + uint32_t _size256; + apache::thrift::protocol::TType _etype259; + iprot->readListBegin(_etype259, _size256); + (*(this->success)).resize(_size256); + uint32_t _i260; + for (_i260 = 0; _i260 < _size256; ++_i260) + { + xfer += (*(this->success))[_i260].read(iprot); + } + iprot->readListEnd(); + } + this->__isset.success = true; + } else { + xfer += iprot->skip(ftype); + } + break; + case 1: + if (ftype == apache::thrift::protocol::T_STRUCT) { + xfer += this->o1.read(iprot); + this->__isset.o1 = true; + } else { + xfer += iprot->skip(ftype); + } + break; + default: + xfer += iprot->skip(ftype); + break; + } + xfer += iprot->readFieldEnd(); + } + + xfer += iprot->readStructEnd(); + + return xfer; +} + uint32_t ThriftHiveMetastore_alter_partition_args::read(apache::thrift::protocol::TProtocol* iprot) { uint32_t xfer = 0; @@ -6922,14 +7174,14 @@ if (ftype == apache::thrift::protocol::T_LIST) { { this->success.clear(); - uint32_t _size250; - apache::thrift::protocol::TType _etype253; - iprot->readListBegin(_etype253, _size250); - this->success.resize(_size250); - uint32_t _i254; - for (_i254 = 0; _i254 < _size250; ++_i254) + uint32_t _size261; + apache::thrift::protocol::TType _etype264; + iprot->readListBegin(_etype264, _size261); + this->success.resize(_size261); + uint32_t _i265; + for (_i265 = 0; _i265 < _size261; ++_i265) { - xfer += iprot->readString(this->success[_i254]); + xfer += iprot->readString(this->success[_i265]); } iprot->readListEnd(); } @@ -6968,10 +7220,10 @@ xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_LIST, 0); { xfer += oprot->writeListBegin(apache::thrift::protocol::T_STRING, this->success.size()); - std::vector ::const_iterator _iter255; - for (_iter255 = this->success.begin(); _iter255 != this->success.end(); ++_iter255) + std::vector ::const_iterator _iter266; + for (_iter266 = this->success.begin(); _iter266 != this->success.end(); ++_iter266) { - xfer += oprot->writeString((*_iter255)); + xfer += oprot->writeString((*_iter266)); } xfer += oprot->writeListEnd(); } @@ -7010,14 +7262,14 @@ if (ftype == apache::thrift::protocol::T_LIST) { { (*(this->success)).clear(); - uint32_t _size256; - apache::thrift::protocol::TType _etype259; - iprot->readListBegin(_etype259, _size256); - (*(this->success)).resize(_size256); - uint32_t _i260; - for (_i260 = 0; _i260 < _size256; ++_i260) + uint32_t _size267; + apache::thrift::protocol::TType _etype270; + iprot->readListBegin(_etype270, _size267); + (*(this->success)).resize(_size267); + uint32_t _i271; + for (_i271 = 0; _i271 < _size267; ++_i271) { - xfer += iprot->readString((*(this->success))[_i260]); + xfer += iprot->readString((*(this->success))[_i271]); } iprot->readListEnd(); } @@ -7132,17 +7384,17 @@ if (ftype == apache::thrift::protocol::T_MAP) { { this->success.clear(); - uint32_t _size261; - apache::thrift::protocol::TType _ktype262; - apache::thrift::protocol::TType _vtype263; - iprot->readMapBegin(_ktype262, _vtype263, _size261); - uint32_t _i265; - for (_i265 = 0; _i265 < _size261; ++_i265) + uint32_t _size272; + apache::thrift::protocol::TType _ktype273; + apache::thrift::protocol::TType _vtype274; + iprot->readMapBegin(_ktype273, _vtype274, _size272); + uint32_t _i276; + for (_i276 = 0; _i276 < _size272; ++_i276) { - std::string _key266; - xfer += iprot->readString(_key266); - std::string& _val267 = this->success[_key266]; - xfer += iprot->readString(_val267); + std::string _key277; + xfer += iprot->readString(_key277); + std::string& _val278 = this->success[_key277]; + xfer += iprot->readString(_val278); } iprot->readMapEnd(); } @@ -7181,11 +7433,11 @@ xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_MAP, 0); { xfer += oprot->writeMapBegin(apache::thrift::protocol::T_STRING, apache::thrift::protocol::T_STRING, this->success.size()); - std::map ::const_iterator _iter268; - for (_iter268 = this->success.begin(); _iter268 != this->success.end(); ++_iter268) + std::map ::const_iterator _iter279; + for (_iter279 = this->success.begin(); _iter279 != this->success.end(); ++_iter279) { - xfer += oprot->writeString(_iter268->first); - xfer += oprot->writeString(_iter268->second); + xfer += oprot->writeString(_iter279->first); + xfer += oprot->writeString(_iter279->second); } xfer += oprot->writeMapEnd(); } @@ -7224,17 +7476,17 @@ if (ftype == apache::thrift::protocol::T_MAP) { { (*(this->success)).clear(); - uint32_t _size269; - apache::thrift::protocol::TType _ktype270; - apache::thrift::protocol::TType _vtype271; - iprot->readMapBegin(_ktype270, _vtype271, _size269); - uint32_t _i273; - for (_i273 = 0; _i273 < _size269; ++_i273) + uint32_t _size280; + apache::thrift::protocol::TType _ktype281; + apache::thrift::protocol::TType _vtype282; + iprot->readMapBegin(_ktype281, _vtype282, _size280); + uint32_t _i284; + for (_i284 = 0; _i284 < _size280; ++_i284) { - std::string _key274; - xfer += iprot->readString(_key274); - std::string& _val275 = (*(this->success))[_key274]; - xfer += iprot->readString(_val275); + std::string _key285; + xfer += iprot->readString(_key285); + std::string& _val286 = (*(this->success))[_key285]; + xfer += iprot->readString(_val286); } iprot->readMapEnd(); } @@ -8075,14 +8327,14 @@ if (ftype == apache::thrift::protocol::T_LIST) { { this->success.clear(); - uint32_t _size276; - apache::thrift::protocol::TType _etype279; - iprot->readListBegin(_etype279, _size276); - this->success.resize(_size276); - uint32_t _i280; - for (_i280 = 0; _i280 < _size276; ++_i280) + uint32_t _size287; + apache::thrift::protocol::TType _etype290; + iprot->readListBegin(_etype290, _size287); + this->success.resize(_size287); + uint32_t _i291; + for (_i291 = 0; _i291 < _size287; ++_i291) { - xfer += this->success[_i280].read(iprot); + xfer += this->success[_i291].read(iprot); } iprot->readListEnd(); } @@ -8129,10 +8381,10 @@ xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_LIST, 0); { xfer += oprot->writeListBegin(apache::thrift::protocol::T_STRUCT, this->success.size()); - std::vector ::const_iterator _iter281; - for (_iter281 = this->success.begin(); _iter281 != this->success.end(); ++_iter281) + std::vector ::const_iterator _iter292; + for (_iter292 = this->success.begin(); _iter292 != this->success.end(); ++_iter292) { - xfer += (*_iter281).write(oprot); + xfer += (*_iter292).write(oprot); } xfer += oprot->writeListEnd(); } @@ -8175,14 +8427,14 @@ if (ftype == apache::thrift::protocol::T_LIST) { { (*(this->success)).clear(); - uint32_t _size282; - apache::thrift::protocol::TType _etype285; - iprot->readListBegin(_etype285, _size282); - (*(this->success)).resize(_size282); - uint32_t _i286; - for (_i286 = 0; _i286 < _size282; ++_i286) + uint32_t _size293; + apache::thrift::protocol::TType _etype296; + iprot->readListBegin(_etype296, _size293); + (*(this->success)).resize(_size293); + uint32_t _i297; + for (_i297 = 0; _i297 < _size293; ++_i297) { - xfer += (*(this->success))[_i286].read(iprot); + xfer += (*(this->success))[_i297].read(iprot); } iprot->readListEnd(); } @@ -8333,14 +8585,14 @@ if (ftype == apache::thrift::protocol::T_LIST) { { this->success.clear(); - uint32_t _size287; - apache::thrift::protocol::TType _etype290; - iprot->readListBegin(_etype290, _size287); - this->success.resize(_size287); - uint32_t _i291; - for (_i291 = 0; _i291 < _size287; ++_i291) + uint32_t _size298; + apache::thrift::protocol::TType _etype301; + iprot->readListBegin(_etype301, _size298); + this->success.resize(_size298); + uint32_t _i302; + for (_i302 = 0; _i302 < _size298; ++_i302) { - xfer += iprot->readString(this->success[_i291]); + xfer += iprot->readString(this->success[_i302]); } iprot->readListEnd(); } @@ -8379,10 +8631,10 @@ xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_LIST, 0); { xfer += oprot->writeListBegin(apache::thrift::protocol::T_STRING, this->success.size()); - std::vector ::const_iterator _iter292; - for (_iter292 = this->success.begin(); _iter292 != this->success.end(); ++_iter292) + std::vector ::const_iterator _iter303; + for (_iter303 = this->success.begin(); _iter303 != this->success.end(); ++_iter303) { - xfer += oprot->writeString((*_iter292)); + xfer += oprot->writeString((*_iter303)); } xfer += oprot->writeListEnd(); } @@ -8421,14 +8673,14 @@ if (ftype == apache::thrift::protocol::T_LIST) { { (*(this->success)).clear(); - uint32_t _size293; - apache::thrift::protocol::TType _etype296; - iprot->readListBegin(_etype296, _size293); - (*(this->success)).resize(_size293); - uint32_t _i297; - for (_i297 = 0; _i297 < _size293; ++_i297) + uint32_t _size304; + apache::thrift::protocol::TType _etype307; + iprot->readListBegin(_etype307, _size304); + (*(this->success)).resize(_size304); + uint32_t _i308; + for (_i308 = 0; _i308 < _size304; ++_i308) { - xfer += iprot->readString((*(this->success))[_i297]); + xfer += iprot->readString((*(this->success))[_i308]); } iprot->readListEnd(); } @@ -10318,6 +10570,72 @@ throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "get_partition_names_ps failed: unknown result"); } +void ThriftHiveMetastoreClient::get_partitions_by_filter(std::vector & _return, const std::string& db_name, const std::string& tbl_name, const std::string& filter, const int16_t max_parts) +{ + send_get_partitions_by_filter(db_name, tbl_name, filter, max_parts); + recv_get_partitions_by_filter(_return); +} + +void ThriftHiveMetastoreClient::send_get_partitions_by_filter(const std::string& db_name, const std::string& tbl_name, const std::string& filter, const int16_t max_parts) +{ + int32_t cseqid = 0; + oprot_->writeMessageBegin("get_partitions_by_filter", apache::thrift::protocol::T_CALL, cseqid); + + ThriftHiveMetastore_get_partitions_by_filter_pargs args; + args.db_name = &db_name; + args.tbl_name = &tbl_name; + args.filter = &filter; + args.max_parts = &max_parts; + args.write(oprot_); + + oprot_->writeMessageEnd(); + oprot_->getTransport()->flush(); + oprot_->getTransport()->writeEnd(); +} + +void ThriftHiveMetastoreClient::recv_get_partitions_by_filter(std::vector & _return) +{ + + int32_t rseqid = 0; + std::string fname; + apache::thrift::protocol::TMessageType mtype; + + iprot_->readMessageBegin(fname, mtype, rseqid); + if (mtype == apache::thrift::protocol::T_EXCEPTION) { + apache::thrift::TApplicationException x; + x.read(iprot_); + iprot_->readMessageEnd(); + iprot_->getTransport()->readEnd(); + throw x; + } + if (mtype != apache::thrift::protocol::T_REPLY) { + iprot_->skip(apache::thrift::protocol::T_STRUCT); + iprot_->readMessageEnd(); + iprot_->getTransport()->readEnd(); + throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); + } + if (fname.compare("get_partitions_by_filter") != 0) { + iprot_->skip(apache::thrift::protocol::T_STRUCT); + iprot_->readMessageEnd(); + iprot_->getTransport()->readEnd(); + throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); + } + ThriftHiveMetastore_get_partitions_by_filter_presult result; + result.success = &_return; + result.read(iprot_); + iprot_->readMessageEnd(); + iprot_->getTransport()->readEnd(); + + if (result.__isset.success) { + // _return pointer has now been filled + return; + } + if (result.__isset.o1) { + throw result.o1; + } + throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "get_partitions_by_filter failed: unknown result"); +} + void ThriftHiveMetastoreClient::alter_partition(const std::string& db_name, const std::string& tbl_name, const Partition& new_part) { send_alter_partition(db_name, tbl_name, new_part); @@ -11900,6 +12218,37 @@ oprot->getTransport()->writeEnd(); } +void ThriftHiveMetastoreProcessor::process_get_partitions_by_filter(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) +{ + ThriftHiveMetastore_get_partitions_by_filter_args args; + args.read(iprot); + iprot->readMessageEnd(); + iprot->getTransport()->readEnd(); + + ThriftHiveMetastore_get_partitions_by_filter_result result; + try { + iface_->get_partitions_by_filter(result.success, args.db_name, args.tbl_name, args.filter, args.max_parts); + result.__isset.success = true; + } catch (MetaException &o1) { + result.o1 = o1; + result.__isset.o1 = true; + } catch (const std::exception& e) { + apache::thrift::TApplicationException x(e.what()); + oprot->writeMessageBegin("get_partitions_by_filter", apache::thrift::protocol::T_EXCEPTION, seqid); + x.write(oprot); + oprot->writeMessageEnd(); + oprot->getTransport()->flush(); + oprot->getTransport()->writeEnd(); + return; + } + + oprot->writeMessageBegin("get_partitions_by_filter", apache::thrift::protocol::T_REPLY, seqid); + result.write(oprot); + oprot->writeMessageEnd(); + oprot->getTransport()->flush(); + oprot->getTransport()->writeEnd(); +} + void ThriftHiveMetastoreProcessor::process_alter_partition(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) { ThriftHiveMetastore_alter_partition_args args; Index: metastore/src/gen-cpp/ThriftHiveMetastore.h =================================================================== --- metastore/src/gen-cpp/ThriftHiveMetastore.h (revision 991274) +++ metastore/src/gen-cpp/ThriftHiveMetastore.h (working copy) @@ -43,6 +43,7 @@ virtual void get_partition_names(std::vector & _return, const std::string& db_name, const std::string& tbl_name, const int16_t max_parts) = 0; virtual void get_partitions_ps(std::vector & _return, const std::string& db_name, const std::string& tbl_name, const std::vector & part_vals, const int16_t max_parts) = 0; virtual void get_partition_names_ps(std::vector & _return, const std::string& db_name, const std::string& tbl_name, const std::vector & part_vals, const int16_t max_parts) = 0; + virtual void get_partitions_by_filter(std::vector & _return, const std::string& db_name, const std::string& tbl_name, const std::string& filter, const int16_t max_parts) = 0; virtual void alter_partition(const std::string& db_name, const std::string& tbl_name, const Partition& new_part) = 0; virtual void get_config_value(std::string& _return, const std::string& name, const std::string& defaultValue) = 0; virtual void partition_name_to_vals(std::vector & _return, const std::string& part_name) = 0; @@ -145,6 +146,9 @@ void get_partition_names_ps(std::vector & /* _return */, const std::string& /* db_name */, const std::string& /* tbl_name */, const std::vector & /* part_vals */, const int16_t /* max_parts */) { return; } + void get_partitions_by_filter(std::vector & /* _return */, const std::string& /* db_name */, const std::string& /* tbl_name */, const std::string& /* filter */, const int16_t /* max_parts */) { + return; + } void alter_partition(const std::string& /* db_name */, const std::string& /* tbl_name */, const Partition& /* new_part */) { return; } @@ -3253,6 +3257,120 @@ }; +class ThriftHiveMetastore_get_partitions_by_filter_args { + public: + + ThriftHiveMetastore_get_partitions_by_filter_args() : db_name(""), tbl_name(""), filter(""), max_parts(-1) { + } + + virtual ~ThriftHiveMetastore_get_partitions_by_filter_args() throw() {} + + std::string db_name; + std::string tbl_name; + std::string filter; + int16_t max_parts; + + struct __isset { + __isset() : db_name(false), tbl_name(false), filter(false), max_parts(false) {} + bool db_name; + bool tbl_name; + bool filter; + bool max_parts; + } __isset; + + bool operator == (const ThriftHiveMetastore_get_partitions_by_filter_args & rhs) const + { + if (!(db_name == rhs.db_name)) + return false; + if (!(tbl_name == rhs.tbl_name)) + return false; + if (!(filter == rhs.filter)) + return false; + if (!(max_parts == rhs.max_parts)) + return false; + return true; + } + bool operator != (const ThriftHiveMetastore_get_partitions_by_filter_args &rhs) const { + return !(*this == rhs); + } + + bool operator < (const ThriftHiveMetastore_get_partitions_by_filter_args & ) const; + + uint32_t read(apache::thrift::protocol::TProtocol* iprot); + uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; + +}; + +class ThriftHiveMetastore_get_partitions_by_filter_pargs { + public: + + + virtual ~ThriftHiveMetastore_get_partitions_by_filter_pargs() throw() {} + + const std::string* db_name; + const std::string* tbl_name; + const std::string* filter; + const int16_t* max_parts; + + uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; + +}; + +class ThriftHiveMetastore_get_partitions_by_filter_result { + public: + + ThriftHiveMetastore_get_partitions_by_filter_result() { + } + + virtual ~ThriftHiveMetastore_get_partitions_by_filter_result() throw() {} + + std::vector success; + MetaException o1; + + struct __isset { + __isset() : success(false), o1(false) {} + bool success; + bool o1; + } __isset; + + bool operator == (const ThriftHiveMetastore_get_partitions_by_filter_result & rhs) const + { + if (!(success == rhs.success)) + return false; + if (!(o1 == rhs.o1)) + return false; + return true; + } + bool operator != (const ThriftHiveMetastore_get_partitions_by_filter_result &rhs) const { + return !(*this == rhs); + } + + bool operator < (const ThriftHiveMetastore_get_partitions_by_filter_result & ) const; + + uint32_t read(apache::thrift::protocol::TProtocol* iprot); + uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; + +}; + +class ThriftHiveMetastore_get_partitions_by_filter_presult { + public: + + + virtual ~ThriftHiveMetastore_get_partitions_by_filter_presult() throw() {} + + std::vector * success; + MetaException o1; + + struct __isset { + __isset() : success(false), o1(false) {} + bool success; + bool o1; + } __isset; + + uint32_t read(apache::thrift::protocol::TProtocol* iprot); + +}; + class ThriftHiveMetastore_alter_partition_args { public: @@ -4335,6 +4453,9 @@ void get_partition_names_ps(std::vector & _return, const std::string& db_name, const std::string& tbl_name, const std::vector & part_vals, const int16_t max_parts); void send_get_partition_names_ps(const std::string& db_name, const std::string& tbl_name, const std::vector & part_vals, const int16_t max_parts); void recv_get_partition_names_ps(std::vector & _return); + void get_partitions_by_filter(std::vector & _return, const std::string& db_name, const std::string& tbl_name, const std::string& filter, const int16_t max_parts); + void send_get_partitions_by_filter(const std::string& db_name, const std::string& tbl_name, const std::string& filter, const int16_t max_parts); + void recv_get_partitions_by_filter(std::vector & _return); void alter_partition(const std::string& db_name, const std::string& tbl_name, const Partition& new_part); void send_alter_partition(const std::string& db_name, const std::string& tbl_name, const Partition& new_part); void recv_alter_partition(); @@ -4398,6 +4519,7 @@ void process_get_partition_names(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); void process_get_partitions_ps(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); void process_get_partition_names_ps(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); + void process_get_partitions_by_filter(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); void process_alter_partition(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); void process_get_config_value(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); void process_partition_name_to_vals(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); @@ -4439,6 +4561,7 @@ processMap_["get_partition_names"] = &ThriftHiveMetastoreProcessor::process_get_partition_names; processMap_["get_partitions_ps"] = &ThriftHiveMetastoreProcessor::process_get_partitions_ps; processMap_["get_partition_names_ps"] = &ThriftHiveMetastoreProcessor::process_get_partition_names_ps; + processMap_["get_partitions_by_filter"] = &ThriftHiveMetastoreProcessor::process_get_partitions_by_filter; processMap_["alter_partition"] = &ThriftHiveMetastoreProcessor::process_alter_partition; processMap_["get_config_value"] = &ThriftHiveMetastoreProcessor::process_get_config_value; processMap_["partition_name_to_vals"] = &ThriftHiveMetastoreProcessor::process_partition_name_to_vals; @@ -4778,6 +4901,18 @@ } } + void get_partitions_by_filter(std::vector & _return, const std::string& db_name, const std::string& tbl_name, const std::string& filter, const int16_t max_parts) { + uint32_t sz = ifaces_.size(); + for (uint32_t i = 0; i < sz; ++i) { + if (i == sz - 1) { + ifaces_[i]->get_partitions_by_filter(_return, db_name, tbl_name, filter, max_parts); + return; + } else { + ifaces_[i]->get_partitions_by_filter(_return, db_name, tbl_name, filter, max_parts); + } + } + } + void alter_partition(const std::string& db_name, const std::string& tbl_name, const Partition& new_part) { uint32_t sz = ifaces_.size(); for (uint32_t i = 0; i < sz; ++i) { Index: metastore/src/gen-cpp/ThriftHiveMetastore_server.skeleton.cpp =================================================================== --- metastore/src/gen-cpp/ThriftHiveMetastore_server.skeleton.cpp (revision 991274) +++ metastore/src/gen-cpp/ThriftHiveMetastore_server.skeleton.cpp (working copy) @@ -162,6 +162,11 @@ printf("get_partition_names_ps\n"); } + void get_partitions_by_filter(std::vector & _return, const std::string& db_name, const std::string& tbl_name, const std::string& filter, const int16_t max_parts) { + // Your implementation goes here + printf("get_partitions_by_filter\n"); + } + void alter_partition(const std::string& db_name, const std::string& tbl_name, const Partition& new_part) { // Your implementation goes here printf("alter_partition\n"); Index: metastore/src/gen-javabean/org/apache/hadoop/hive/metastore/api/ThriftHiveMetastore.java =================================================================== --- metastore/src/gen-javabean/org/apache/hadoop/hive/metastore/api/ThriftHiveMetastore.java (revision 991274) +++ metastore/src/gen-javabean/org/apache/hadoop/hive/metastore/api/ThriftHiveMetastore.java (working copy) @@ -81,6 +81,8 @@ public List get_partition_names_ps(String db_name, String tbl_name, List part_vals, short max_parts) throws MetaException, TException; + public List get_partitions_by_filter(String db_name, String tbl_name, String filter, short max_parts) throws MetaException, TException; + public void alter_partition(String db_name, String tbl_name, Partition new_part) throws InvalidOperationException, MetaException, TException; public String get_config_value(String name, String defaultValue) throws ConfigValSecurityException, TException; @@ -1227,6 +1229,45 @@ throw new TApplicationException(TApplicationException.MISSING_RESULT, "get_partition_names_ps failed: unknown result"); } + public List get_partitions_by_filter(String db_name, String tbl_name, String filter, short max_parts) throws MetaException, TException + { + send_get_partitions_by_filter(db_name, tbl_name, filter, max_parts); + return recv_get_partitions_by_filter(); + } + + public void send_get_partitions_by_filter(String db_name, String tbl_name, String filter, short max_parts) throws TException + { + oprot_.writeMessageBegin(new TMessage("get_partitions_by_filter", TMessageType.CALL, seqid_)); + get_partitions_by_filter_args args = new get_partitions_by_filter_args(); + args.db_name = db_name; + args.tbl_name = tbl_name; + args.filter = filter; + args.max_parts = max_parts; + args.write(oprot_); + oprot_.writeMessageEnd(); + oprot_.getTransport().flush(); + } + + public List recv_get_partitions_by_filter() throws MetaException, TException + { + TMessage msg = iprot_.readMessageBegin(); + if (msg.type == TMessageType.EXCEPTION) { + TApplicationException x = TApplicationException.read(iprot_); + iprot_.readMessageEnd(); + throw x; + } + get_partitions_by_filter_result result = new get_partitions_by_filter_result(); + result.read(iprot_); + iprot_.readMessageEnd(); + if (result.isSetSuccess()) { + return result.success; + } + if (result.o1 != null) { + throw result.o1; + } + throw new TApplicationException(TApplicationException.MISSING_RESULT, "get_partitions_by_filter failed: unknown result"); + } + public void alter_partition(String db_name, String tbl_name, Partition new_part) throws InvalidOperationException, MetaException, TException { send_alter_partition(db_name, tbl_name, new_part); @@ -1614,6 +1655,7 @@ processMap_.put("get_partition_names", new get_partition_names()); processMap_.put("get_partitions_ps", new get_partitions_ps()); processMap_.put("get_partition_names_ps", new get_partition_names_ps()); + processMap_.put("get_partitions_by_filter", new get_partitions_by_filter()); processMap_.put("alter_partition", new alter_partition()); processMap_.put("get_config_value", new get_config_value()); processMap_.put("partition_name_to_vals", new partition_name_to_vals()); @@ -2493,6 +2535,34 @@ } + private class get_partitions_by_filter implements ProcessFunction { + public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException + { + get_partitions_by_filter_args args = new get_partitions_by_filter_args(); + args.read(iprot); + iprot.readMessageEnd(); + get_partitions_by_filter_result result = new get_partitions_by_filter_result(); + try { + result.success = iface_.get_partitions_by_filter(args.db_name, args.tbl_name, args.filter, args.max_parts); + } catch (MetaException o1) { + result.o1 = o1; + } catch (Throwable th) { + LOGGER.error("Internal error processing get_partitions_by_filter", th); + TApplicationException x = new TApplicationException(TApplicationException.INTERNAL_ERROR, "Internal error processing get_partitions_by_filter"); + oprot.writeMessageBegin(new TMessage("get_partitions_by_filter", TMessageType.EXCEPTION, seqid)); + x.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + return; + } + oprot.writeMessageBegin(new TMessage("get_partitions_by_filter", TMessageType.REPLY, seqid)); + result.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + } + + } + private class alter_partition implements ProcessFunction { public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException { @@ -19871,6 +19941,699 @@ } + public static class get_partitions_by_filter_args implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("get_partitions_by_filter_args"); + private static final TField DB_NAME_FIELD_DESC = new TField("db_name", TType.STRING, (short)1); + private static final TField TBL_NAME_FIELD_DESC = new TField("tbl_name", TType.STRING, (short)2); + private static final TField FILTER_FIELD_DESC = new TField("filter", TType.STRING, (short)3); + private static final TField MAX_PARTS_FIELD_DESC = new TField("max_parts", TType.I16, (short)4); + + private String db_name; + public static final int DB_NAME = 1; + private String tbl_name; + public static final int TBL_NAME = 2; + private String filter; + public static final int FILTER = 3; + private short max_parts; + public static final int MAX_PARTS = 4; + + private final Isset __isset = new Isset(); + private static final class Isset implements java.io.Serializable { + public boolean max_parts = false; + } + + public static final Map metaDataMap = Collections.unmodifiableMap(new HashMap() {{ + put(DB_NAME, new FieldMetaData("db_name", TFieldRequirementType.DEFAULT, + new FieldValueMetaData(TType.STRING))); + put(TBL_NAME, new FieldMetaData("tbl_name", TFieldRequirementType.DEFAULT, + new FieldValueMetaData(TType.STRING))); + put(FILTER, new FieldMetaData("filter", TFieldRequirementType.DEFAULT, + new FieldValueMetaData(TType.STRING))); + put(MAX_PARTS, new FieldMetaData("max_parts", TFieldRequirementType.DEFAULT, + new FieldValueMetaData(TType.I16))); + }}); + + static { + FieldMetaData.addStructMetaDataMap(get_partitions_by_filter_args.class, metaDataMap); + } + + public get_partitions_by_filter_args() { + this.max_parts = (short)-1; + + } + + public get_partitions_by_filter_args( + String db_name, + String tbl_name, + String filter, + short max_parts) + { + this(); + this.db_name = db_name; + this.tbl_name = tbl_name; + this.filter = filter; + this.max_parts = max_parts; + this.__isset.max_parts = true; + } + + /** + * Performs a deep copy on other. + */ + public get_partitions_by_filter_args(get_partitions_by_filter_args other) { + if (other.isSetDb_name()) { + this.db_name = other.db_name; + } + if (other.isSetTbl_name()) { + this.tbl_name = other.tbl_name; + } + if (other.isSetFilter()) { + this.filter = other.filter; + } + __isset.max_parts = other.__isset.max_parts; + this.max_parts = other.max_parts; + } + + @Override + public get_partitions_by_filter_args clone() { + return new get_partitions_by_filter_args(this); + } + + public String getDb_name() { + return this.db_name; + } + + public void setDb_name(String db_name) { + this.db_name = db_name; + } + + public void unsetDb_name() { + this.db_name = null; + } + + // Returns true if field db_name is set (has been asigned a value) and false otherwise + public boolean isSetDb_name() { + return this.db_name != null; + } + + public String getTbl_name() { + return this.tbl_name; + } + + public void setTbl_name(String tbl_name) { + this.tbl_name = tbl_name; + } + + public void unsetTbl_name() { + this.tbl_name = null; + } + + // Returns true if field tbl_name is set (has been asigned a value) and false otherwise + public boolean isSetTbl_name() { + return this.tbl_name != null; + } + + public String getFilter() { + return this.filter; + } + + public void setFilter(String filter) { + this.filter = filter; + } + + public void unsetFilter() { + this.filter = null; + } + + // Returns true if field filter is set (has been asigned a value) and false otherwise + public boolean isSetFilter() { + return this.filter != null; + } + + public short getMax_parts() { + return this.max_parts; + } + + public void setMax_parts(short max_parts) { + this.max_parts = max_parts; + this.__isset.max_parts = true; + } + + public void unsetMax_parts() { + this.__isset.max_parts = false; + } + + // Returns true if field max_parts is set (has been asigned a value) and false otherwise + public boolean isSetMax_parts() { + return this.__isset.max_parts; + } + + public void setFieldValue(int fieldID, Object value) { + switch (fieldID) { + case DB_NAME: + if (value == null) { + unsetDb_name(); + } else { + setDb_name((String)value); + } + break; + + case TBL_NAME: + if (value == null) { + unsetTbl_name(); + } else { + setTbl_name((String)value); + } + break; + + case FILTER: + if (value == null) { + unsetFilter(); + } else { + setFilter((String)value); + } + break; + + case MAX_PARTS: + if (value == null) { + unsetMax_parts(); + } else { + setMax_parts((Short)value); + } + break; + + default: + throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); + } + } + + public Object getFieldValue(int fieldID) { + switch (fieldID) { + case DB_NAME: + return getDb_name(); + + case TBL_NAME: + return getTbl_name(); + + case FILTER: + return getFilter(); + + case MAX_PARTS: + return new Short(getMax_parts()); + + default: + throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); + } + } + + // Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise + public boolean isSet(int fieldID) { + switch (fieldID) { + case DB_NAME: + return isSetDb_name(); + case TBL_NAME: + return isSetTbl_name(); + case FILTER: + return isSetFilter(); + case MAX_PARTS: + return isSetMax_parts(); + default: + throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); + } + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof get_partitions_by_filter_args) + return this.equals((get_partitions_by_filter_args)that); + return false; + } + + public boolean equals(get_partitions_by_filter_args that) { + if (that == null) + return false; + + boolean this_present_db_name = true && this.isSetDb_name(); + boolean that_present_db_name = true && that.isSetDb_name(); + if (this_present_db_name || that_present_db_name) { + if (!(this_present_db_name && that_present_db_name)) + return false; + if (!this.db_name.equals(that.db_name)) + return false; + } + + boolean this_present_tbl_name = true && this.isSetTbl_name(); + boolean that_present_tbl_name = true && that.isSetTbl_name(); + if (this_present_tbl_name || that_present_tbl_name) { + if (!(this_present_tbl_name && that_present_tbl_name)) + return false; + if (!this.tbl_name.equals(that.tbl_name)) + return false; + } + + boolean this_present_filter = true && this.isSetFilter(); + boolean that_present_filter = true && that.isSetFilter(); + if (this_present_filter || that_present_filter) { + if (!(this_present_filter && that_present_filter)) + return false; + if (!this.filter.equals(that.filter)) + return false; + } + + boolean this_present_max_parts = true; + boolean that_present_max_parts = true; + if (this_present_max_parts || that_present_max_parts) { + if (!(this_present_max_parts && that_present_max_parts)) + return false; + if (this.max_parts != that.max_parts) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public void read(TProtocol iprot) throws TException { + TField field; + iprot.readStructBegin(); + while (true) + { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) + { + case DB_NAME: + if (field.type == TType.STRING) { + this.db_name = iprot.readString(); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case TBL_NAME: + if (field.type == TType.STRING) { + this.tbl_name = iprot.readString(); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case FILTER: + if (field.type == TType.STRING) { + this.filter = iprot.readString(); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case MAX_PARTS: + if (field.type == TType.I16) { + this.max_parts = iprot.readI16(); + this.__isset.max_parts = true; + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + default: + TProtocolUtil.skip(iprot, field.type); + break; + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + validate(); + } + + public void write(TProtocol oprot) throws TException { + validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (this.db_name != null) { + oprot.writeFieldBegin(DB_NAME_FIELD_DESC); + oprot.writeString(this.db_name); + oprot.writeFieldEnd(); + } + if (this.tbl_name != null) { + oprot.writeFieldBegin(TBL_NAME_FIELD_DESC); + oprot.writeString(this.tbl_name); + oprot.writeFieldEnd(); + } + if (this.filter != null) { + oprot.writeFieldBegin(FILTER_FIELD_DESC); + oprot.writeString(this.filter); + oprot.writeFieldEnd(); + } + oprot.writeFieldBegin(MAX_PARTS_FIELD_DESC); + oprot.writeI16(this.max_parts); + oprot.writeFieldEnd(); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("get_partitions_by_filter_args("); + boolean first = true; + + sb.append("db_name:"); + if (this.db_name == null) { + sb.append("null"); + } else { + sb.append(this.db_name); + } + first = false; + if (!first) sb.append(", "); + sb.append("tbl_name:"); + if (this.tbl_name == null) { + sb.append("null"); + } else { + sb.append(this.tbl_name); + } + first = false; + if (!first) sb.append(", "); + sb.append("filter:"); + if (this.filter == null) { + sb.append("null"); + } else { + sb.append(this.filter); + } + first = false; + if (!first) sb.append(", "); + sb.append("max_parts:"); + sb.append(this.max_parts); + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws TException { + // check for required fields + // check that fields of type enum have valid values + } + + } + + public static class get_partitions_by_filter_result implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("get_partitions_by_filter_result"); + private static final TField SUCCESS_FIELD_DESC = new TField("success", TType.LIST, (short)0); + private static final TField O1_FIELD_DESC = new TField("o1", TType.STRUCT, (short)1); + + private List success; + public static final int SUCCESS = 0; + private MetaException o1; + public static final int O1 = 1; + + private final Isset __isset = new Isset(); + private static final class Isset implements java.io.Serializable { + } + + public static final Map metaDataMap = Collections.unmodifiableMap(new HashMap() {{ + put(SUCCESS, new FieldMetaData("success", TFieldRequirementType.DEFAULT, + new ListMetaData(TType.LIST, + new StructMetaData(TType.STRUCT, Partition.class)))); + put(O1, new FieldMetaData("o1", TFieldRequirementType.DEFAULT, + new FieldValueMetaData(TType.STRUCT))); + }}); + + static { + FieldMetaData.addStructMetaDataMap(get_partitions_by_filter_result.class, metaDataMap); + } + + public get_partitions_by_filter_result() { + } + + public get_partitions_by_filter_result( + List success, + MetaException o1) + { + this(); + this.success = success; + this.o1 = o1; + } + + /** + * Performs a deep copy on other. + */ + public get_partitions_by_filter_result(get_partitions_by_filter_result other) { + if (other.isSetSuccess()) { + List __this__success = new ArrayList(); + for (Partition other_element : other.success) { + __this__success.add(new Partition(other_element)); + } + this.success = __this__success; + } + if (other.isSetO1()) { + this.o1 = new MetaException(other.o1); + } + } + + @Override + public get_partitions_by_filter_result clone() { + return new get_partitions_by_filter_result(this); + } + + public int getSuccessSize() { + return (this.success == null) ? 0 : this.success.size(); + } + + public java.util.Iterator getSuccessIterator() { + return (this.success == null) ? null : this.success.iterator(); + } + + public void addToSuccess(Partition elem) { + if (this.success == null) { + this.success = new ArrayList(); + } + this.success.add(elem); + } + + public List getSuccess() { + return this.success; + } + + public void setSuccess(List success) { + this.success = success; + } + + public void unsetSuccess() { + this.success = null; + } + + // Returns true if field success is set (has been asigned a value) and false otherwise + public boolean isSetSuccess() { + return this.success != null; + } + + public MetaException getO1() { + return this.o1; + } + + public void setO1(MetaException o1) { + this.o1 = o1; + } + + public void unsetO1() { + this.o1 = null; + } + + // Returns true if field o1 is set (has been asigned a value) and false otherwise + public boolean isSetO1() { + return this.o1 != null; + } + + public void setFieldValue(int fieldID, Object value) { + switch (fieldID) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((List)value); + } + break; + + case O1: + if (value == null) { + unsetO1(); + } else { + setO1((MetaException)value); + } + break; + + default: + throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); + } + } + + public Object getFieldValue(int fieldID) { + switch (fieldID) { + case SUCCESS: + return getSuccess(); + + case O1: + return getO1(); + + default: + throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); + } + } + + // Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise + public boolean isSet(int fieldID) { + switch (fieldID) { + case SUCCESS: + return isSetSuccess(); + case O1: + return isSetO1(); + default: + throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!"); + } + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof get_partitions_by_filter_result) + return this.equals((get_partitions_by_filter_result)that); + return false; + } + + public boolean equals(get_partitions_by_filter_result that) { + if (that == null) + return false; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + boolean this_present_o1 = true && this.isSetO1(); + boolean that_present_o1 = true && that.isSetO1(); + if (this_present_o1 || that_present_o1) { + if (!(this_present_o1 && that_present_o1)) + return false; + if (!this.o1.equals(that.o1)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + public void read(TProtocol iprot) throws TException { + TField field; + iprot.readStructBegin(); + while (true) + { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) + { + case SUCCESS: + if (field.type == TType.LIST) { + { + TList _list123 = iprot.readListBegin(); + this.success = new ArrayList(_list123.size); + for (int _i124 = 0; _i124 < _list123.size; ++_i124) + { + Partition _elem125; + _elem125 = new Partition(); + _elem125.read(iprot); + this.success.add(_elem125); + } + iprot.readListEnd(); + } + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case O1: + if (field.type == TType.STRUCT) { + this.o1 = new MetaException(); + this.o1.read(iprot); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + default: + TProtocolUtil.skip(iprot, field.type); + break; + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + validate(); + } + + public void write(TProtocol oprot) throws TException { + oprot.writeStructBegin(STRUCT_DESC); + + if (this.isSetSuccess()) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + { + oprot.writeListBegin(new TList(TType.STRUCT, this.success.size())); + for (Partition _iter126 : this.success) { + _iter126.write(oprot); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } else if (this.isSetO1()) { + oprot.writeFieldBegin(O1_FIELD_DESC); + this.o1.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("get_partitions_by_filter_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + if (!first) sb.append(", "); + sb.append("o1:"); + if (this.o1 == null) { + sb.append("null"); + } else { + sb.append(this.o1); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws TException { + // check for required fields + // check that fields of type enum have valid values + } + + } + public static class alter_partition_args implements TBase, java.io.Serializable, Cloneable { private static final TStruct STRUCT_DESC = new TStruct("alter_partition_args"); private static final TField DB_NAME_FIELD_DESC = new TField("db_name", TType.STRING, (short)1); @@ -21380,13 +22143,13 @@ case SUCCESS: if (field.type == TType.LIST) { { - TList _list123 = iprot.readListBegin(); - this.success = new ArrayList(_list123.size); - for (int _i124 = 0; _i124 < _list123.size; ++_i124) + TList _list127 = iprot.readListBegin(); + this.success = new ArrayList(_list127.size); + for (int _i128 = 0; _i128 < _list127.size; ++_i128) { - String _elem125; - _elem125 = iprot.readString(); - this.success.add(_elem125); + String _elem129; + _elem129 = iprot.readString(); + this.success.add(_elem129); } iprot.readListEnd(); } @@ -21420,8 +22183,8 @@ oprot.writeFieldBegin(SUCCESS_FIELD_DESC); { oprot.writeListBegin(new TList(TType.STRING, this.success.size())); - for (String _iter126 : this.success) { - oprot.writeString(_iter126); + for (String _iter130 : this.success) { + oprot.writeString(_iter130); } oprot.writeListEnd(); } @@ -21871,15 +22634,15 @@ case SUCCESS: if (field.type == TType.MAP) { { - TMap _map127 = iprot.readMapBegin(); - this.success = new HashMap(2*_map127.size); - for (int _i128 = 0; _i128 < _map127.size; ++_i128) + TMap _map131 = iprot.readMapBegin(); + this.success = new HashMap(2*_map131.size); + for (int _i132 = 0; _i132 < _map131.size; ++_i132) { - String _key129; - String _val130; - _key129 = iprot.readString(); - _val130 = iprot.readString(); - this.success.put(_key129, _val130); + String _key133; + String _val134; + _key133 = iprot.readString(); + _val134 = iprot.readString(); + this.success.put(_key133, _val134); } iprot.readMapEnd(); } @@ -21913,9 +22676,9 @@ oprot.writeFieldBegin(SUCCESS_FIELD_DESC); { oprot.writeMapBegin(new TMap(TType.STRING, TType.STRING, this.success.size())); - for (Map.Entry _iter131 : this.success.entrySet()) { - oprot.writeString(_iter131.getKey()); - oprot.writeString(_iter131.getValue()); + for (Map.Entry _iter135 : this.success.entrySet()) { + oprot.writeString(_iter135.getKey()); + oprot.writeString(_iter135.getValue()); } oprot.writeMapEnd(); } @@ -24586,14 +25349,14 @@ case SUCCESS: if (field.type == TType.LIST) { { - TList _list132 = iprot.readListBegin(); - this.success = new ArrayList(_list132.size); - for (int _i133 = 0; _i133 < _list132.size; ++_i133) + TList _list136 = iprot.readListBegin(); + this.success = new ArrayList(_list136.size); + for (int _i137 = 0; _i137 < _list136.size; ++_i137) { - Index _elem134; - _elem134 = new Index(); - _elem134.read(iprot); - this.success.add(_elem134); + Index _elem138; + _elem138 = new Index(); + _elem138.read(iprot); + this.success.add(_elem138); } iprot.readListEnd(); } @@ -24635,8 +25398,8 @@ oprot.writeFieldBegin(SUCCESS_FIELD_DESC); { oprot.writeListBegin(new TList(TType.STRUCT, this.success.size())); - for (Index _iter135 : this.success) { - _iter135.write(oprot); + for (Index _iter139 : this.success) { + _iter139.write(oprot); } oprot.writeListEnd(); } @@ -25230,13 +25993,13 @@ case SUCCESS: if (field.type == TType.LIST) { { - TList _list136 = iprot.readListBegin(); - this.success = new ArrayList(_list136.size); - for (int _i137 = 0; _i137 < _list136.size; ++_i137) + TList _list140 = iprot.readListBegin(); + this.success = new ArrayList(_list140.size); + for (int _i141 = 0; _i141 < _list140.size; ++_i141) { - String _elem138; - _elem138 = iprot.readString(); - this.success.add(_elem138); + String _elem142; + _elem142 = iprot.readString(); + this.success.add(_elem142); } iprot.readListEnd(); } @@ -25270,8 +26033,8 @@ oprot.writeFieldBegin(SUCCESS_FIELD_DESC); { oprot.writeListBegin(new TList(TType.STRING, this.success.size())); - for (String _iter139 : this.success) { - oprot.writeString(_iter139); + for (String _iter143 : this.success) { + oprot.writeString(_iter143); } oprot.writeListEnd(); } Index: metastore/src/gen-php/ThriftHiveMetastore.php =================================================================== --- metastore/src/gen-php/ThriftHiveMetastore.php (revision 991274) +++ metastore/src/gen-php/ThriftHiveMetastore.php (working copy) @@ -38,6 +38,7 @@ public function get_partition_names($db_name, $tbl_name, $max_parts); public function get_partitions_ps($db_name, $tbl_name, $part_vals, $max_parts); public function get_partition_names_ps($db_name, $tbl_name, $part_vals, $max_parts); + public function get_partitions_by_filter($db_name, $tbl_name, $filter, $max_parts); public function alter_partition($db_name, $tbl_name, $new_part); public function get_config_value($name, $defaultValue); public function partition_name_to_vals($part_name); @@ -1673,6 +1674,63 @@ throw new Exception("get_partition_names_ps failed: unknown result"); } + public function get_partitions_by_filter($db_name, $tbl_name, $filter, $max_parts) + { + $this->send_get_partitions_by_filter($db_name, $tbl_name, $filter, $max_parts); + return $this->recv_get_partitions_by_filter(); + } + + public function send_get_partitions_by_filter($db_name, $tbl_name, $filter, $max_parts) + { + $args = new metastore_ThriftHiveMetastore_get_partitions_by_filter_args(); + $args->db_name = $db_name; + $args->tbl_name = $tbl_name; + $args->filter = $filter; + $args->max_parts = $max_parts; + $bin_accel = ($this->output_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_write_binary'); + if ($bin_accel) + { + thrift_protocol_write_binary($this->output_, 'get_partitions_by_filter', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite()); + } + else + { + $this->output_->writeMessageBegin('get_partitions_by_filter', TMessageType::CALL, $this->seqid_); + $args->write($this->output_); + $this->output_->writeMessageEnd(); + $this->output_->getTransport()->flush(); + } + } + + public function recv_get_partitions_by_filter() + { + $bin_accel = ($this->input_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_read_binary'); + if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, 'metastore_ThriftHiveMetastore_get_partitions_by_filter_result', $this->input_->isStrictRead()); + else + { + $rseqid = 0; + $fname = null; + $mtype = 0; + + $this->input_->readMessageBegin($fname, $mtype, $rseqid); + if ($mtype == TMessageType::EXCEPTION) { + $x = new TApplicationException(); + $x->read($this->input_); + $this->input_->readMessageEnd(); + throw $x; + } + $result = new metastore_ThriftHiveMetastore_get_partitions_by_filter_result(); + $result->read($this->input_); + $this->input_->readMessageEnd(); + } + if ($result->success !== null) { + return $result->success; + } + if ($result->o1 !== null) { + throw $result->o1; + } + throw new Exception("get_partitions_by_filter failed: unknown result"); + } + public function alter_partition($db_name, $tbl_name, $new_part) { $this->send_alter_partition($db_name, $tbl_name, $new_part); @@ -8536,6 +8594,260 @@ } +class metastore_ThriftHiveMetastore_get_partitions_by_filter_args { + static $_TSPEC; + + public $db_name = null; + public $tbl_name = null; + public $filter = null; + public $max_parts = -1; + + public function __construct($vals=null) { + if (!isset(self::$_TSPEC)) { + self::$_TSPEC = array( + 1 => array( + 'var' => 'db_name', + 'type' => TType::STRING, + ), + 2 => array( + 'var' => 'tbl_name', + 'type' => TType::STRING, + ), + 3 => array( + 'var' => 'filter', + 'type' => TType::STRING, + ), + 4 => array( + 'var' => 'max_parts', + 'type' => TType::I16, + ), + ); + } + if (is_array($vals)) { + if (isset($vals['db_name'])) { + $this->db_name = $vals['db_name']; + } + if (isset($vals['tbl_name'])) { + $this->tbl_name = $vals['tbl_name']; + } + if (isset($vals['filter'])) { + $this->filter = $vals['filter']; + } + if (isset($vals['max_parts'])) { + $this->max_parts = $vals['max_parts']; + } + } + } + + public function getName() { + return 'ThriftHiveMetastore_get_partitions_by_filter_args'; + } + + public function read($input) + { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) + { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) + { + case 1: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->db_name); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->tbl_name); + } else { + $xfer += $input->skip($ftype); + } + break; + case 3: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->filter); + } else { + $xfer += $input->skip($ftype); + } + break; + case 4: + if ($ftype == TType::I16) { + $xfer += $input->readI16($this->max_parts); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) { + $xfer = 0; + $xfer += $output->writeStructBegin('ThriftHiveMetastore_get_partitions_by_filter_args'); + if ($this->db_name !== null) { + $xfer += $output->writeFieldBegin('db_name', TType::STRING, 1); + $xfer += $output->writeString($this->db_name); + $xfer += $output->writeFieldEnd(); + } + if ($this->tbl_name !== null) { + $xfer += $output->writeFieldBegin('tbl_name', TType::STRING, 2); + $xfer += $output->writeString($this->tbl_name); + $xfer += $output->writeFieldEnd(); + } + if ($this->filter !== null) { + $xfer += $output->writeFieldBegin('filter', TType::STRING, 3); + $xfer += $output->writeString($this->filter); + $xfer += $output->writeFieldEnd(); + } + if ($this->max_parts !== null) { + $xfer += $output->writeFieldBegin('max_parts', TType::I16, 4); + $xfer += $output->writeI16($this->max_parts); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } + +} + +class metastore_ThriftHiveMetastore_get_partitions_by_filter_result { + static $_TSPEC; + + public $success = null; + public $o1 = null; + + public function __construct($vals=null) { + if (!isset(self::$_TSPEC)) { + self::$_TSPEC = array( + 0 => array( + 'var' => 'success', + 'type' => TType::LST, + 'etype' => TType::STRUCT, + 'elem' => array( + 'type' => TType::STRUCT, + 'class' => 'metastore_Partition', + ), + ), + 1 => array( + 'var' => 'o1', + 'type' => TType::STRUCT, + 'class' => 'metastore_MetaException', + ), + ); + } + if (is_array($vals)) { + if (isset($vals['success'])) { + $this->success = $vals['success']; + } + if (isset($vals['o1'])) { + $this->o1 = $vals['o1']; + } + } + } + + public function getName() { + return 'ThriftHiveMetastore_get_partitions_by_filter_result'; + } + + public function read($input) + { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) + { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) + { + case 0: + if ($ftype == TType::LST) { + $this->success = array(); + $_size217 = 0; + $_etype220 = 0; + $xfer += $input->readListBegin($_etype220, $_size217); + for ($_i221 = 0; $_i221 < $_size217; ++$_i221) + { + $elem222 = null; + $elem222 = new metastore_Partition(); + $xfer += $elem222->read($input); + $this->success []= $elem222; + } + $xfer += $input->readListEnd(); + } else { + $xfer += $input->skip($ftype); + } + break; + case 1: + if ($ftype == TType::STRUCT) { + $this->o1 = new metastore_MetaException(); + $xfer += $this->o1->read($input); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) { + $xfer = 0; + $xfer += $output->writeStructBegin('ThriftHiveMetastore_get_partitions_by_filter_result'); + if ($this->success !== null) { + if (!is_array($this->success)) { + throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA); + } + $xfer += $output->writeFieldBegin('success', TType::LST, 0); + { + $output->writeListBegin(TType::STRUCT, count($this->success)); + { + foreach ($this->success as $iter223) + { + $xfer += $iter223->write($output); + } + } + $output->writeListEnd(); + } + $xfer += $output->writeFieldEnd(); + } + if ($this->o1 !== null) { + $xfer += $output->writeFieldBegin('o1', TType::STRUCT, 1); + $xfer += $this->o1->write($output); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } + +} + class metastore_ThriftHiveMetastore_alter_partition_args { static $_TSPEC; @@ -9063,14 +9375,14 @@ case 0: if ($ftype == TType::LST) { $this->success = array(); - $_size217 = 0; - $_etype220 = 0; - $xfer += $input->readListBegin($_etype220, $_size217); - for ($_i221 = 0; $_i221 < $_size217; ++$_i221) + $_size224 = 0; + $_etype227 = 0; + $xfer += $input->readListBegin($_etype227, $_size224); + for ($_i228 = 0; $_i228 < $_size224; ++$_i228) { - $elem222 = null; - $xfer += $input->readString($elem222); - $this->success []= $elem222; + $elem229 = null; + $xfer += $input->readString($elem229); + $this->success []= $elem229; } $xfer += $input->readListEnd(); } else { @@ -9106,9 +9418,9 @@ { $output->writeListBegin(TType::STRING, count($this->success)); { - foreach ($this->success as $iter223) + foreach ($this->success as $iter230) { - $xfer += $output->writeString($iter223); + $xfer += $output->writeString($iter230); } } $output->writeListEnd(); @@ -9259,17 +9571,17 @@ case 0: if ($ftype == TType::MAP) { $this->success = array(); - $_size224 = 0; - $_ktype225 = 0; - $_vtype226 = 0; - $xfer += $input->readMapBegin($_ktype225, $_vtype226, $_size224); - for ($_i228 = 0; $_i228 < $_size224; ++$_i228) + $_size231 = 0; + $_ktype232 = 0; + $_vtype233 = 0; + $xfer += $input->readMapBegin($_ktype232, $_vtype233, $_size231); + for ($_i235 = 0; $_i235 < $_size231; ++$_i235) { - $key229 = ''; - $val230 = ''; - $xfer += $input->readString($key229); - $xfer += $input->readString($val230); - $this->success[$key229] = $val230; + $key236 = ''; + $val237 = ''; + $xfer += $input->readString($key236); + $xfer += $input->readString($val237); + $this->success[$key236] = $val237; } $xfer += $input->readMapEnd(); } else { @@ -9305,10 +9617,10 @@ { $output->writeMapBegin(TType::STRING, TType::STRING, count($this->success)); { - foreach ($this->success as $kiter231 => $viter232) + foreach ($this->success as $kiter238 => $viter239) { - $xfer += $output->writeString($kiter231); - $xfer += $output->writeString($viter232); + $xfer += $output->writeString($kiter238); + $xfer += $output->writeString($viter239); } } $output->writeMapEnd(); @@ -10231,15 +10543,15 @@ case 0: if ($ftype == TType::LST) { $this->success = array(); - $_size233 = 0; - $_etype236 = 0; - $xfer += $input->readListBegin($_etype236, $_size233); - for ($_i237 = 0; $_i237 < $_size233; ++$_i237) + $_size240 = 0; + $_etype243 = 0; + $xfer += $input->readListBegin($_etype243, $_size240); + for ($_i244 = 0; $_i244 < $_size240; ++$_i244) { - $elem238 = null; - $elem238 = new metastore_Index(); - $xfer += $elem238->read($input); - $this->success []= $elem238; + $elem245 = null; + $elem245 = new metastore_Index(); + $xfer += $elem245->read($input); + $this->success []= $elem245; } $xfer += $input->readListEnd(); } else { @@ -10283,9 +10595,9 @@ { $output->writeListBegin(TType::STRUCT, count($this->success)); { - foreach ($this->success as $iter239) + foreach ($this->success as $iter246) { - $xfer += $iter239->write($output); + $xfer += $iter246->write($output); } } $output->writeListEnd(); @@ -10477,14 +10789,14 @@ case 0: if ($ftype == TType::LST) { $this->success = array(); - $_size240 = 0; - $_etype243 = 0; - $xfer += $input->readListBegin($_etype243, $_size240); - for ($_i244 = 0; $_i244 < $_size240; ++$_i244) + $_size247 = 0; + $_etype250 = 0; + $xfer += $input->readListBegin($_etype250, $_size247); + for ($_i251 = 0; $_i251 < $_size247; ++$_i251) { - $elem245 = null; - $xfer += $input->readString($elem245); - $this->success []= $elem245; + $elem252 = null; + $xfer += $input->readString($elem252); + $this->success []= $elem252; } $xfer += $input->readListEnd(); } else { @@ -10520,9 +10832,9 @@ { $output->writeListBegin(TType::STRING, count($this->success)); { - foreach ($this->success as $iter246) + foreach ($this->success as $iter253) { - $xfer += $output->writeString($iter246); + $xfer += $output->writeString($iter253); } } $output->writeListEnd(); Index: metastore/if/hive_metastore.thrift =================================================================== --- metastore/if/hive_metastore.thrift (revision 991397) +++ metastore/if/hive_metastore.thrift (working copy) @@ -228,6 +228,11 @@ 2:string tbl_name, 3:list part_vals, 4:i16 max_parts=-1) throws(1:MetaException o1) + // get the partitions matching the given partition filter + list get_partitions_by_filter(1:string db_name 2:string tbl_name + 3:string filter, 4:i16 max_parts=-1) + throws(1:MetaException o1) + // changes the partition to the new partition object. partition is identified from the part values // in the new_part void alter_partition(1:string db_name, 2:string tbl_name, 3:Partition new_part) Index: metastore/build.xml =================================================================== --- metastore/build.xml (revision 991274) +++ metastore/build.xml (working copy) @@ -29,11 +29,20 @@ - + + + + + +