示例#1
0
def test_total_04():
    """
    {
    "select": [
        "订单号"
    ],
    "condition_and": [
        "客户名称 = 京东商城"
    ],
    "condition_or": [],
    "order_by_desc": [],
    "group_by": [],
    "having": [],
    "result_limit": null,
    "date_from": null,
    "data_to": null
    }
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "查询京东商城的订单编号"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    s1.condition_parser()
    from ch2sql.output import Output
    o = Output(s1)
    print(o.get_json())
示例#2
0
def test_condition_parser1():
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "查询最高平均不含税金额大于1000的数据"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    print(s1.select_parser())
    s1.condition_parser()
示例#3
0
def test_total_01():
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "京东商城税费小于10的单据日期"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    s1.condition_parser()
    print(s1.select_targets)
    print(s1.conditions)
示例#4
0
def test_total_17():
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "订单编号大于50的客户名称"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    s1.condition_parser()
    from ch2sql.output import Output
    o = Output(s1)
    print(o.get_json())
示例#5
0
def test_condition_parser3():
    """
    带有逻辑连接符号的纯值条件节点解析
    eg. '销售部或者电子商务部'
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "销售部或者电子商务部的情况"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.condition_parser()
示例#6
0
def test_condition_parser2():
    """
    测试值条件节点的处理情况
    eg: "京东商城的平均单价"
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "京东商城的平均单价"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    print(s1.select_parser())
    s1.condition_parser()
示例#7
0
def test_condition_parser4():
    """
    对包含group by top修饰的属性名条件节点解析
    eg. "各部门的平均税费"
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "各部门名称的平均税款"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    print(s1.select_targets)
    s1.condition_parser()
示例#8
0
def test_total_08():
    """
     在这种情况下会出现混乱
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "各业务员的总订单金额"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    s1.condition_parser()
    from ch2sql.output import Output
    o = Output(s1)
    print(o.get_json())
示例#9
0
def test_condition_parser6():
    """
    top
    eg. "利润top10的部门名称"
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "不同部门名称的利润均值"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    s1.select_parser()
    s1.condition_parser()
    print(s1.select_targets)
    print(s1.conditions)
示例#10
0
def test_total_20():
    """
    {
    "select": [
        "利润"
    ],
    "condition_and": [
        "客户名称 = 淘宝网"
    ],
    "condition_or": [],
    "order_by_desc": [],
    "group_by": [],
    "having": [],
    "result_limit": null,
    "date_from": "2014-12-01",
    "date_to": "2014-12-31"
     }
    :return:
    """

    s1 = "2014年12月淘宝网的利润"
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    print(s1.parser_tree)
    s1.select_parser()
    s1.condition_parser()
    from ch2sql.output import Output
    o = Output(s1)
    print(o.get_json())
示例#11
0
def test_total_19():
    """
    {
    "select": [
        "COUNT(订单号)",
        "部门名称"
    ],
    "condition_and": [],
    "condition_or": [],
    "order_by_desc": [],
    "group_by": [
        "部门名称"
    ],
    "having": [],
    "result_limit": null,
    "date_from": "None",
    "date_to": "None"
   }
    :return:
    """
    from ch2sql.sentence import Sentence
    from ch2sql.database import Table
    from ch2sql.parser import Parser
    import os
    path = "../datasource/销售业绩报表.xlsx"
    assert os.path.exists(path)
    path = os.path.abspath(path)
    table = Table(table_name='销售业绩报表', path=path)
    s1 = "各部门名称的订单号总数"
    s1 = Sentence(s1, table)
    print(s1.nodes)
    s1 = Parser(s1)
    print(s1.parser_tree)
    s1.select_parser()
    s1.condition_parser()
    from ch2sql.output import Output
    o = Output(s1)
    print(o.get_json())