Initial project source
这个提交包含在:
@@ -0,0 +1,29 @@
|
||||
package cn.aixunkeji.datagov.dataproduct.bi;
|
||||
|
||||
import cn.aixunkeji.datagov.integration.api.tablefile.AnalyticsQuery;
|
||||
import cn.aixunkeji.datagov.integration.tablefile.AnalyticsSqlCompiler;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
/** Source-file fixture only: actual production compiler and Owner validation, no database access here. */
|
||||
public final class BiTimeBucketMysqlProbe {
|
||||
static String encode(String value){return Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8));}
|
||||
static String decode(String value){return value.equals("-")?null:new String(Base64.getDecoder().decode(value),StandardCharsets.UTF_8);}
|
||||
public static void main(String[] args)throws ReflectiveOperationException {
|
||||
String mode=args[0],unit=args[1];if(!Set.of("DAY","WEEK","MONTH","QUARTER","YEAR","FISCAL_QUARTER","FISCAL_YEAR").contains(unit))throw new IllegalArgumentException();
|
||||
Integer fiscalMonth=args.length>3?Integer.valueOf(args[3]):null;
|
||||
if(mode.equals("compile")){
|
||||
var filters=new ArrayList<AnalyticsQuery.Filter>();filters.add(new AnalyticsQuery.Filter("tenant","EQ",List.of("fixture' OR 1=1 --")));
|
||||
if(args.length>2&&!args[2].equals("-"))filters.add(new AnalyticsQuery.Filter("day","GTE",List.of(args[2])));
|
||||
var plan=new AnalyticsQuery.Plan(List.of(),List.of("day"),List.of(new AnalyticsQuery.Measure("amount","AVG","average"),new AnalyticsQuery.Measure("person","COUNT_DISTINCT","people")),filters,List.of(new AnalyticsQuery.Sort("day","ASC")),50,false,null,new AnalyticsQuery.TimeBucket("day",unit,fiscalMonth));
|
||||
var sql=AnalyticsSqlCompiler.compileForSource(plan,List.of("day","amount","person","tenant"),"MYSQL","aixun_datagov_system",null,"bi_date_fixture");
|
||||
System.out.println(encode(sql.sql()));System.out.println(String.join(",",sql.parameters().stream().map(BiTimeBucketMysqlProbe::encode).toList()));return;
|
||||
}
|
||||
if(!mode.equals("validate"))throw new IllegalArgumentException();
|
||||
var rows=new ArrayList<Map<String,String>>();try(var input=new Scanner(System.in,StandardCharsets.UTF_8)){while(input.hasNextLine()){String[] values=input.nextLine().split("\\t",-1);if(values.length!=3)throw new IllegalArgumentException();var row=new LinkedHashMap<String,String>();row.put("day",decode(values[0]));row.put("average",decode(values[1]));row.put("people",decode(values[2]));rows.add(row);}}
|
||||
var bucket=new BiQuerySource.TimeBucket("day",unit,fiscalMonth);var plan=new BiQuerySource.Plan(List.of("day","amount","person"),List.of("day"),List.of(new BiQuerySource.Measure("amount","AVG","average"),new BiQuerySource.Measure("person","COUNT_DISTINCT","people")),List.of(),List.of(),50,false,null,bucket);
|
||||
var returned=new BiQuerySource.Result("SUCCEEDED",List.of("day","average","people"),rows,false,LocalDateTime.now(),null,null,Map.of(),null,null,bucket);
|
||||
var owner=Class.forName("cn.aixunkeji.datagov.dataproduct.bi.BiTimeBuckets").getDeclaredMethod("result",BiQuerySource.Plan.class,BiQuerySource.Result.class);owner.setAccessible(true);owner.invoke(null,plan,returned);System.out.println("SUCCEEDED\t"+rows.size());
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户