Skip to content

Commit

Permalink
还没调通.
Browse files Browse the repository at this point in the history
  • Loading branch information
ninqing committed Jul 30, 2016
1 parent 2343f93 commit e73e9cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 267 deletions.
42 changes: 9 additions & 33 deletions tddl-sample/src/main/java/com/taobao/tddl/sample/Sample.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.taobao.tddl.sample;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.jdbc.core.JdbcTemplate;

import com.taobao.tddl.common.exception.TddlException;
import com.taobao.tddl.matrix.jdbc.TDataSource;
Expand All @@ -18,38 +15,17 @@ public static void main(String[] args) throws TddlException, SQLException {

ds.setAppName("test_app");
ds.setRuleFile("rule.xml");

Map cp = new HashMap();
cp.put("ALLOW_TEMPORARY_TABLE", "True");

ds.setConnectionProperties(cp);

ds.init();

System.out.println("init done");

Connection conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement("SELECT a.custId, a.id,b.adgroupid, SUM(c.cost) / SUM(c.click) AS ppc,c.thedate, c.memberid, c.campaignid, c.productlineid, c.adgroupid, SUM(c.impression), SUM(c.cost), SUM(c.click), SUM(c.click) / SUM(c.impression) AS ctr, b.title, a.onlinestate, a.reason FROM Lunaadgroup a join lunaadgroupinfo b on a.id=b.adgroupid LEFT JOIN rpt_solar_adgroup_ob c ON a.id = c.adgroupid where a.custid='1102000884' and b.custid='1102000884' and b.title like '%办公室%' GROUP BY c.thedate, c.memberid, c.campaignid, c.productlineid, c.adgroupid HAVING ppc > 1 ORDER BY ppc DESC");

long start = System.currentTimeMillis();
ResultSet rs = ps.executeQuery();
while (rs.next()) {
StringBuilder sb = new StringBuilder();
int count = rs.getMetaData().getColumnCount();
for (int i = 1; i <= count; i++) {

String key = rs.getMetaData().getColumnLabel(i);
Object val = rs.getObject(i);
sb.append("[" + rs.getMetaData().getTableName(i) + "." + key + "->" + val + "]");
}
System.out.println(sb.toString());
}

rs.close();
ps.close();
conn.close();

System.out.println("done " + (System.currentTimeMillis() - start));
JdbcTemplate jt0 = new JdbcTemplate(ds);
jt0.update("delete from test_table");
System.out.println(jt0.update("insert into test_table values(1,'name1')"));
System.out.println(jt0.update("insert into test_table values(2,'name1')"));
System.out.println(jt0.update("insert into test_table values(3,'name1')"));
System.out.println(jt0.update("insert into test_table values(4,'name1')"));

}

}
253 changes: 19 additions & 234 deletions tddl-sample/src/main/resources/rule.xml
Original file line number Diff line number Diff line change
@@ -1,245 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="vtabroot" class="com.taobao.tddl.rule.VirtualTableRoot" init-method="init">
<property name="dbType" value="MYSQL" />
<property name="defaultDbIndex" value="SUBWAY_DEV_G_GROUP" />
</bean>

<bean id="basePartionDBRule" class="com.taobao.tddl.interact.rule.TableRule"
abstract="true">
<property name="dbNamePattern" value="SUBWAY_DEV_P{00}_GROUP" />
<property name="dbRuleArray">
<value>(#custId,64,2048#.longValue() %2048).intdiv(64)</value>

<bean id="vtabroot" class="com.taobao.tddl.rule.VirtualTableRoot"
init-method="init">
<property name="defaultDbIndex" value="tddl_test_0"/>
<!-- 请修改成应用默认的group -->
<property name="dbType" value="MYSQL"></property>
<property name="tableRules">
<map>
<entry key="test_table" value-ref="test_table" />
</map>
</property>
<property name="allowFullTableScan" value="true" />
</bean>

<bean id="basePartionTableRule" class="com.taobao.tddl.interact.rule.TableRule"
parent="basePartionDBRule" abstract="true">
<bean id="test_table" class="com.taobao.tddl.rule.config.TableRule">
<property name="dbNamePattern" value="tddl_test_{0}" />
<property name="dbRuleArray">
<value>((#id,1,4#)%4).intdiv(2)</value>
</property>
<property name="tbNamePattern" value="test_table_{00}" />
<property name="tbRuleArray">
<value>#custId,64,2048#.longValue() % 32</value>
<value>#id,1,4#.longValue() % 4</value>
</property>
<property name="allowFullTableScan" value="true"/>
</bean>

<!-- item module start -->
<bean id="lunaadgroup" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunaadgroup" />
</bean>

<bean id="lunaadgrouphis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunaadgrouphis" />
</bean>

<bean id="lunaadgroupinfo" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunaadgroupinfo" />
</bean>

<bean id="lunaadgroupplace" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunaadgroupplace" />
</bean>

<bean id="lunaadgroupplacehis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunaadgroupplacehis" />
</bean>

<bean id="lunabidword" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionTableRule">
<property name="tbNamePattern" value="lunabidword_{0000}" />
</bean>

<bean id="lunabidwordhis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionTableRule">
<property name="tbNamePattern" value="lunabidwordhis_{0000}" />
</bean>

<bean id="lunacatmatch" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacatmatch" />
</bean>

<bean id="lunacatmatchhis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacatmatchhis" />
</bean>

<bean id="lunacreative" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacreative" />
</bean>

<bean id="lunacreativehis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacreativehis" />
</bean>

<bean id="lunacreativeelement" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacreativeelement" />
</bean>

<bean id="lunacreativehiselement" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacreativehiselement" />
</bean>

<bean id="lunacreativerecord" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacreativerecord" />
</bean>

<bean id="lunacreativerecordelement" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacreativerecordelement" />
</bean>
<!-- item module end -->

<!-- quick module start -->
<bean id="lunacampbidword" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacampbidword" />
</bean>

<bean id="lunacampitem" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacampitem" />
</bean>
<!-- quick module end -->

<!-- wbitem module start -->
<bean id="lunacategoryrecord" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacategoryrecord" />
</bean>
<!-- wbitem module end -->

<!-- page module start -->
<bean id="lunapageadgroup" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapageadgroup" />
</bean>

<bean id="lunapageadgrouphis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapageadgrouphis" />
</bean>

<bean id="lunapageadgroupinfo" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapageadgroupinfo" />
</bean>

<bean id="lunapageadgroupplace" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapageadgroupplace" />
</bean>

<bean id="lunapageadgroupplacehis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapageadgroupplacehis" />
</bean>

<bean id="lunapagebidword" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapagebidword" />
</bean>

<bean id="lunapagebidwordhis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapagebidwordhis" />
</bean>

<bean id="lunapagecatmatch" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapagecatmatch" />
</bean>

<bean id="lunapagecatmatchhis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapagecatmatchhis" />
</bean>

<bean id="lunapagecreative" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapagecreative" />
</bean>

<bean id="lunapagecreativehis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapagecreativehis" />
</bean>

<bean id="lunapagecreativerecord" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunapagecreativerecord" />
</bean>
<!-- page module end -->

<!-- campaign module start -->
<bean id="lunaareasetting" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunaareasetting" />
</bean>

<bean id="lunabidsetting" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunabidsetting" />
</bean>

<bean id="lunabidsettinghis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunabidsettinghis" />
</bean>

<bean id="lunacampaign" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacampaign" />
</bean>

<bean id="lunacampaignhis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunacampaignhis" />
</bean>

<bean id="lunademographicsetting" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunademographicsetting" />
</bean>

<bean id="lunaplsetting" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunaplsetting" />
</bean>

<bean id="lunaremindsetting" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunaremindsetting" />
</bean>

<bean id="lunaremindlog" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunaremindlog" />
</bean>

<bean id="lunatimesetting" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunatimesetting" />
</bean>

<bean id="lunatimetemplete" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunatimetemplete" />
</bean>
<!-- campaign module end -->

<!-- rpt module start -->
<bean id="lunarptdimensionfilter" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunarptdimensionfilter" />
</bean>

<bean id="lunadimensionsetting" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunadimensionsetting" />
</bean>

<bean id="lunarptfieldsetting" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunarptfieldsetting" />
</bean>


<bean id="lunarptfiletask" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunarptfiletask" />
</bean>
<bean id="lunarptfilesubtask" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunarptfilesubtask" />
</bean>
<bean id="lunarptfiletaskref" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionDBRule">
<property name="tbNamePattern" value="lunarptfiletaskref" />
</bean>

<!-- rpt module end -->

<!-- tag module start -->
<bean id="lunaadgrouptag" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionTableRule">
<property name="tbNamePattern" value="lunaadgrouptag_{0000}" />
</bean>

<bean id="lunaadgrouptaghis" class="com.taobao.tddl.interact.rule.TableRule" parent="basePartionTableRule">
<property name="tbNamePattern" value="lunaadgrouptaghis_{0000}" />
</bean>
<!-- tag module end -->



<!-- ob table start -->
<bean id="rpt_solar_adgroup_ob" class="com.taobao.tddl.interact.rule.TableRule">
<property name="tbNamePattern" value="rpt_solar_adgroup_ob" />
<property name="dbNamePattern" value="ob_group" />
</bean>
<!-- ob table end -->



</beans>

0 comments on commit e73e9cd

Please sign in to comment.