In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Default library table insert (supported) @ Test public void testUserWrite () {User user = new User (); user.setAge (10); user.setName ("Zhang San"); user.setPhone ("15157181986"); user.setSex (1); user.setUpdateTime (new Date ()) User.setCreateTime (new Date ()); userMapper.insert (user); System.out.println ("userId:" + user.getUserId ());} single table aggregation query count (supported) @ Test public void testShardingReadCount () {OrderExample ex = new OrderExample (); long count = orderMapper.countByExample (ex) System.out.println ("count:" + count);} order by,limit (supported) @ Test public void testShardingReadLimit () {OrderExample ex = new OrderExample (); ex.setLimit (2); ex.setOffset (21); ex.setOrderByClause ("user_id desc"); List orders = orderMapper.selectByExample (ex) Orders.stream () .forEach (o-> {System.out.println ("userId:" + o.getUserId () + "orderId:" + o.getOrderId ();});} group by (support) @ Getter@Setterpublic class GroupResult implements Serializable {private Long userId; private Integer cnt } select user_id, count (1) as cnt from t_order group by user_id @ Test public void testShardingReadGroupBy () {List userOrderCounts = orderMapper.getUserOrderCount (); userOrderCounts.forEach (u-> System.out.println ("userId:" + u.getUserId () + "count:" + u.getCnt () } single table and sub-table associated queries (only broadcast table and sub-table associated queries are supported)
Single table: a logical table that does not split the database (such as t_user in this example) subtable: a logical table (such as t_order in this example) broadcast table: refers to the table that exists in all sharding data sources, and the table structure and the data in the table are exactly the same in each database. It is suitable for scenarios where the amount of data is small and needs to be associated with tables with massive data, such as dictionary tables. (reference to this concept: broadcast table)
Here, a single table is associated with a sub-table, and there must be a single table (that is, a broadcast table) in each database, otherwise the query cannot be associated. As in the following statement, it cannot be executed in this example. Because the t_order logical table in this example is scattered across two libraries, the t_user table must have one in both libraries to associate queries.
Select id, u.user_id as userId, order_id as orderId, title, content, u.create_time as createTime, u.update_time as updateTime, `name`, age, sex, phone from t_user u join t_order o on u.user_id = o.user_id where u.age > # {age,jdbcType=INTEGER} above are how to use Sphere in Sharding to implement data sub-database and sub-table operations) The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.