当前位置: 首页>>代码示例>>Python>>正文


Python SqlSelect.parse方法代码示例

本文整理汇总了Python中es_sql.sqlparse.sql_select.SqlSelect.parse方法的典型用法代码示例。如果您正苦于以下问题:Python SqlSelect.parse方法的具体用法?Python SqlSelect.parse怎么用?Python SqlSelect.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在es_sql.sqlparse.sql_select.SqlSelect的用法示例。


在下文中一共展示了SqlSelect.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_group_by_case_when

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_group_by_case_when(self):
     sql_select = SqlSelect.parse(
         "SELECT * FROM symbol GROUP BY CASE WHEN price > 10 THEN 'high' ELSE 'low' END AS hl")
     self.assertEqual(['hl'], sql_select.group_by.keys())
     self.assertEqual(stypes.Case, type(sql_select.group_by['hl']))
     sql_select = SqlSelect.parse(
         "SELECT * FROM symbol GROUP BY ( CASE WHEN price > 10 THEN 'high' ELSE 'low' END) AS hl")
     self.assertEqual(['hl'], sql_select.group_by.keys())
     self.assertEqual(stypes.Case, type(sql_select.group_by['hl']))
开发者ID:saki-saki,项目名称:es-monitor,代码行数:11,代码来源:sql_select_test.py

示例2: test_is

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_is(self):
     sql_select = SqlSelect.parse("SELECT * FROM symbol WHERE a IS NULL")
     comparison = sql_select.where.tokens[-1]
     self.assertEqual(stypes.Comparison, type(comparison))
     self.assertEqual("IS", comparison.operator)
     self.assertEqual("a", str(comparison.left))
     self.assertEqual("NULL", str(comparison.right))
开发者ID:yangyinchun,项目名称:es-monitor,代码行数:9,代码来源:sql_select_test.py

示例3: test_is_not

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_is_not(self):
     sql_select = SqlSelect.parse('SELECT * FROM symbol WHERE a IS  NOT NULL')
     comparison = sql_select.where.tokens[-1]
     self.assertEqual(stypes.Comparison, type(comparison))
     self.assertEqual('IS  NOT', comparison.operator)
     self.assertEqual('a', str(comparison.left))
     self.assertEqual('NULL', str(comparison.right))
开发者ID:saki-saki,项目名称:es-monitor,代码行数:9,代码来源:sql_select_test.py

示例4: test_bigger_than

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_bigger_than(self):
     sql_select = SqlSelect.parse("SELECT * FROM symbol HAVING a > 0 ORDER BY name")
     comparison = sql_select.having[-2]
     self.assertEqual(stypes.Comparison, type(comparison))
     self.assertEqual(">", comparison.operator)
     self.assertEqual("a", str(comparison.left))
     self.assertEqual("0", str(comparison.right))
开发者ID:yangyinchun,项目名称:es-monitor,代码行数:9,代码来源:sql_select_test.py

示例5: test_bigger_than_function_expression

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_bigger_than_function_expression(self):
     sql_select = SqlSelect.parse("SELECT * FROM symbol WHERE a > now() - INTERVAL '5 DAYS'")
     comparison = sql_select.where.tokens[-1]
     self.assertEqual(stypes.Comparison, type(comparison))
     self.assertEqual(">", comparison.operator)
     self.assertEqual("a", str(comparison.left))
     self.assertEqual("now() - eval_datetime('INTERVAL', '5 DAYS')", str(comparison.right))
开发者ID:yangyinchun,项目名称:es-monitor,代码行数:9,代码来源:sql_select_test.py

示例6: test_support_now_and_interval

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_support_now_and_interval(self):
     datetime_evaluator.NOW = datetime.datetime(2015, 1, 2)
     sql_select = SqlSelect.parse(
         "SELECT * FROM index('symbol-%Y-%m-%d', now()-interval('1 days'), timestamp('2015-01-03 00:00:00')) "
         "AS my_table GROUP BY name"
     )
     self.assertEqual("symbol-2015-01-01,symbol-2015-01-02,symbol-2015-01-03", sql_select.from_indices)
开发者ID:yangyinchun,项目名称:es-monitor,代码行数:9,代码来源:sql_select_test.py

示例7: test_in

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_in(self):
     sql_select = SqlSelect.parse("SELECT * FROM symbol WHERE symbol IN ('AAPL', 'GOOG')")
     comparison = sql_select.where.tokens[-1]
     self.assertEqual(stypes.Comparison, type(comparison))
     self.assertEqual("IN", comparison.operator)
     self.assertEqual("symbol", str(comparison.left))
     self.assertEqual("('AAPL', 'GOOG')", str(comparison.right))
开发者ID:yangyinchun,项目名称:es-monitor,代码行数:9,代码来源:sql_select_test.py

示例8: test_not_in

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_not_in(self):
     sql_select = SqlSelect.parse("SELECT * FROM symbol WHERE a NOT IN (1,2,3)")
     comparison = sql_select.where.tokens[-1]
     self.assertEqual(stypes.Comparison, type(comparison))
     self.assertEqual("NOT IN", comparison.operator)
     self.assertEqual("a", str(comparison.left))
     self.assertEqual("(1,2,3)", str(comparison.right))
开发者ID:yangyinchun,项目名称:es-monitor,代码行数:9,代码来源:sql_select_test.py

示例9: test_not_like

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_not_like(self):
     sql_select = SqlSelect.parse("SELECT * FROM symbol WHERE a NOT LIKE 'abc%'")
     comparison = sql_select.where.tokens[-1]
     self.assertEqual(stypes.Comparison, type(comparison))
     self.assertEqual("NOT LIKE", comparison.operator)
     self.assertEqual("a", str(comparison.left))
     self.assertEqual("'abc%'", str(comparison.right))
开发者ID:yangyinchun,项目名称:es-monitor,代码行数:9,代码来源:sql_select_test.py

示例10: test_in

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_in(self):
     sql_select = SqlSelect.parse('SELECT * FROM symbol WHERE a IN (1,2,3)')
     comparison = sql_select.where.tokens[-1]
     self.assertEqual(stypes.Comparison, type(comparison))
     self.assertEqual('IN', comparison.operator)
     self.assertEqual('a', str(comparison.left))
     self.assertEqual('(1,2,3)', str(comparison.right))
开发者ID:saki-saki,项目名称:es-monitor,代码行数:9,代码来源:sql_select_test.py

示例11: test_parameter

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_parameter(self):
     sql_select = SqlSelect.parse("SELECT * FROM symbol WHERE a = %(param)s")
     comparison = sql_select.where.tokens[-1]
     self.assertEqual(stypes.Comparison, type(comparison))
     self.assertEqual("=", comparison.operator)
     self.assertEqual("a", str(comparison.left))
     self.assertEqual("%(param)s", str(comparison.right))
     self.assertEqual(ttypes.Name.Placeholder, comparison.right.ttype)
开发者ID:yangyinchun,项目名称:es-monitor,代码行数:10,代码来源:sql_select_test.py

示例12: test_where_should_not_be_part_of_join_condition

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
    def test_where_should_not_be_part_of_join_condition(self):
        sql_select = SqlSelect.parse(
            """select  phone from cn_tag_data_info_es
join base_info on  cn_tag_data_info_es.phone = base_info.phone
where cn_tag_data_info_es.date_str='2016-07-07'
group by phone
            """)
        self.assertIsNotNone(sql_select.where)
开发者ID:saki-saki,项目名称:es-monitor,代码行数:10,代码来源:sql_select_test.py

示例13: test_projection_is_wildcard

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_projection_is_wildcard(self):
     sql_select = SqlSelect.parse("SELECT * FROM symbol")
     self.assertEqual(["*"], sql_select.projections.keys())
     self.assertEqual(ttypes.Wildcard, sql_select.projections["*"].ttype)
     self.assertIsNone(sql_select.where)
     self.assertEqual(dict(), sql_select.group_by)
     self.assertEqual([], sql_select.order_by)
     self.assertEqual([], sql_select.having)
     self.assertIsNone(sql_select.limit)
开发者ID:yangyinchun,项目名称:es-monitor,代码行数:11,代码来源:sql_select_test.py

示例14: test_projection_is_expression_without_function

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
 def test_projection_is_expression_without_function(self):
     sql_select = SqlSelect.parse("SELECT a/2 AS abc FROM symbol")
     self.assertEqual(["abc"], sql_select.projections.keys())
     self.assertEqual(stypes.Expression, type(sql_select.projections["abc"]))
     self.assertEqual("a/2", str(sql_select.projections["abc"]))
     self.assertIsNone(sql_select.where)
     self.assertEqual(dict(), sql_select.group_by)
     self.assertEqual([], sql_select.order_by)
     self.assertEqual([], sql_select.having)
     self.assertIsNone(sql_select.limit)
开发者ID:yangyinchun,项目名称:es-monitor,代码行数:12,代码来源:sql_select_test.py

示例15: test_group_by_and_having

# 需要导入模块: from es_sql.sqlparse.sql_select import SqlSelect [as 别名]
# 或者: from es_sql.sqlparse.sql_select.SqlSelect import parse [as 别名]
    def test_group_by_and_having(self):
        sql_select = SqlSelect.parse(
            """SELECT phone, sum(cr_car_xiangqing_count) as total_count
  FROM cn_tag_data_info_es
      JOIN base_info ON cn_tag_data_info_es.phone = base_info.phone
 WHERE date_str >= "2016-05-01" and date_str <= "2016-05-03"
 GROUP BY phone
 HAVING total_count > 9""")
        self.assertIsNotNone(sql_select.where)
        self.assertIsNotNone(sql_select.having)
开发者ID:saki-saki,项目名称:es-monitor,代码行数:12,代码来源:sql_select_test.py


注:本文中的es_sql.sqlparse.sql_select.SqlSelect.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。