当前位置: 首页 > 工具软件 > OLAP4J > 使用案例 >

olap4j.jar 生成mdx语句

衡子琪
2023-12-01
public class QuerySentence /*extends TextCase*/{
    public static void main(String[] s){

        ParseTreeNode callNode = new CallNode(null,"iff",Syntax.Function,new IdentifierNode(new NameSegment("aad")));
        ParseTreeNode callNode1 = new CallNode(null,"iff",Syntax.Function,new IdentifierNode(new NameSegment("aadfasdfad")));
        CallNode callNode2 = new CallNode(
                null,
                ",",
                Syntax.Infix,
                callNode,
                callNode1);
//        new IdentifierNode(callNode,callNode1);


        WithMemberNode withMemberNode   = new WithMemberNode(null,
                new IdentifierNode(new NameSegment("paiming")),callNode2,null);

        ArrayList<ParseTreeNode> withMemberNodes = new ArrayList<ParseTreeNode>();
        withMemberNodes.add(withMemberNode);
        SelectNode query = new SelectNode(
                null,
                withMemberNodes,
                new ArrayList<AxisNode>(),
                null,
                null,
                new ArrayList<IdentifierNode>());
        query.setFrom(
                new IdentifierNode(
                        new NameSegment("Sales")));
        query.getAxisList().add(
                new AxisNode(
                        null,
                        false,
                        Axis.ROWS,
                        new ArrayList<IdentifierNode>(),
                        new CallNode(
                                null,
                                "{}",
                                Syntax.Braces,
                                new IdentifierNode(
                                        IdentifierNode.ofNames("Measures").getSegmentList()),
                                        new IdentifierNode(IdentifierNode.ofNames("Unit Sales").getSegmentList()),
                                new CallNode(null,"log",Syntax.Method,new IdentifierNode(new NameSegment("日期")),
                                        LiteralNode.createSymbol(null,"7")))));
//        AxisNode where = new AxisNode(
//                null,
//                false,
//                Axis.FILTER,
//                new ArrayList<IdentifierNode>(),
//                new CallNode(
//                        null,
//                        "{}",
//                        Syntax.Braces,
//                        new IdentifierNode(
//                                IdentifierNode.ofNames("Measures").getSegmentList()),
//                        new IdentifierNode(IdentifierNode.ofNames("Unit Sales").getSegmentList())));
//        query.getFilterAxis().setExpression(new CallNode(
//                null,
//                "{}",
//                Syntax.Braces,
//                new IdentifierNode(
//                        IdentifierNode.ofNames("Measures").getSegmentList()),
//                new IdentifierNode(IdentifierNode.ofNames("Unit Sales").getSegmentList())));
        CallNode where = new CallNode(null, "order", Syntax.Function, new IdentifierNode(
                IdentifierNode.ofNames("Measures").getSegmentList()),
                new IdentifierNode(IdentifierNode.ofNames("Unit Sales").getSegmentList()),
                LiteralNode.createSymbol(null, "asc"));
        query.getFilterAxis().setExpression(where);

        System.out.println(query.toString());
    }


}
1.selectNode
2.IdentifierNode
3.CallNode
4.NameSegment
5.LiteralNode
6.WithMemberNode
7.WithSetNode
 
olap4j官网 文档
 
 类似资料: