def test_not_equals(self): self._fdw._append_filter(self._ml, 'foo', '<>', 'baz') self.assertEqual(self._ml, [{'not': {'term': {'foo': 'baz'}}}]) self._ml = MatchList() self._fdw._append_filter(self._ml, 'foo', '<>', 4) self.assertEqual(self._ml, [{'not': {'term': {'foo': 4}}}]) self._ml = MatchList() self._fdw._append_filter( self._ml, 'foo', '<>', datetime(year=2015, month=8, day=31, hour=10, minute=0, second=30)) self.assertEqual(self._ml, [{ 'not': { 'term': { 'foo': datetime(year=2015, month=8, day=31, hour=10, minute=0, second=30) } } }])
def test_like(self): self._fdw._append_filter(self._ml, 'foo', '~~', 'bar%') self.assertEqual(self._ml, [{'prefix': {'foo': r'bar'}}]) self._ml = MatchList() self._fdw._append_filter(self._ml, 'foo', '~~', '%bar%b_z') self.assertEqual(self._ml, [{'regexp': {'foo': r'.*bar.*b.z'}}]) self._ml = MatchList() self._fdw._append_filter(self._ml, 'foo', '~~', 'foo%bar%') self.assertEqual(self._ml, [{'regexp': {'foo': r'foo.*bar.*'}}]) self._ml = MatchList() self._fdw._append_filter(self._ml, 'foo', '~~', '_bar%') self.assertEqual(self._ml, [{'regexp': {'foo': r'.bar.*'}}])
def test_equals(self): self._fdw._append_filter(self._ml, 'foo', '=', 'bar') self.assertEqual(self._ml, [{'term': {'foo': 'bar'}}]) self._ml = MatchList() self._fdw._append_filter(self._ml, 'foo', '=', 100) self.assertEqual(self._ml, [{'term': {'foo': 100}}]) self._ml = MatchList() self._fdw._append_filter(self._ml, 'foo', '=', datetime(year=2015, month=7, day=1)) self.assertEqual(self._ml, [{ 'term': { 'foo': datetime(year=2015, month=7, day=1) } }])
def test_process_qual(self): must_list = MatchList() must_not_list = MatchList() self._fdw._process_qual(must_list, must_not_list, 'foo', '=', 'bar') self.assertEqual(len(must_list), 1) self.assertEqual(len(must_not_list), 0) self._fdw._process_qual(must_list, must_not_list, 'foo', '<>', 'bar') self.assertEqual(len(must_list), 1) self.assertEqual(len(must_not_list), 1) self._fdw._process_qual(must_list, must_not_list, 'foo', '~~', 'bar%') self.assertEqual(len(must_list), 2) self.assertEqual(len(must_not_list), 1) # Not pushing down ILIKE since we can't write a case-insensitive regexp # filter self._fdw._process_qual(must_list, must_not_list, 'foo', '~~*', 'bar%') self.assertEqual(len(must_list), 2) self.assertEqual(len(must_not_list), 1)
def test_gte(self): self._fdw._append_filter( self._ml, 'foo', '>=', datetime(year=2015, month=12, day=1, hour=13, minute=24, second=59)) self.assertEqual(self._ml, [{ 'range': { 'foo': { 'gte': datetime(year=2015, month=12, day=1, hour=13, minute=24, second=59) } } }]) self._ml = MatchList() self._fdw._append_filter(self._ml, 'foo', '>=', 4) self.assertEqual(self._ml, [{'range': {'foo': {'gte': 4}}}])
def test_range(self): self._fdw._append_filter( self._ml, 'foo', '<@', '["2015-12-01 00:00:00","2015-12-02 01:00:00.123456")') self.assertEqual(self._ml, [{ 'range': { 'foo': { 'gte': '2015-12-01T00:00:00.000000', 'lt': '2015-12-02T01:00:00.123456' } } }]) self._ml = MatchList() self._fdw._append_filter( self._ml, 'foo', '<@', '["2015-12-01 00:00:00.000001","2015-12-02 01:00:00"]') self.assertEqual(self._ml, [{ 'range': { 'foo': { 'gte': '2015-12-01T00:00:00.000001', 'lte': '2015-12-02T01:00:00.000000' } } }]) self._ml = MatchList() self._fdw._append_filter( self._ml, 'foo', '<@', '("2015-12-01 00:00:00","2015-12-02 01:00:00"]') self.assertEqual(self._ml, [{ 'range': { 'foo': { 'gt': '2015-12-01T00:00:00.000000', 'lte': '2015-12-02T01:00:00.000000' } } }]) self._ml = MatchList() self._fdw._append_filter( self._ml, 'foo', '<@', '("2015-12-01 00:00:00.123456","2015-12-02 01:00:00.987654")') self.assertEqual(self._ml, [{ 'range': { 'foo': { 'gt': '2015-12-01T00:00:00.123456', 'lt': '2015-12-02T01:00:00.987654' } } }]) self._ml = MatchList() self._fdw._append_filter(self._ml, 'foo', '<@', '[-1,5]') self.assertEqual(self._ml, [{ 'range': { 'foo': { 'gte': '-1', 'lte': '5' } } }])
def setUp(self): self._fdw = ESForeignDataWrapper({'doc_type': 'foo'}, []) self._ml = MatchList()