leiyiz commented on a change in pull request #12580: URL: https://github.com/apache/beam/pull/12580#discussion_r470453149
########## File path: sdks/python/apache_beam/testing/benchmarks/nexmark/queries/query3.py ########## @@ -0,0 +1,164 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +""" +Query 3, 'Local Item Suggestion'. Who is selling in OR, ID or CA in category +10, and for what auction ids? In CQL syntax:: + + SELECT Istream(P.name, P.city, P.state, A.id) + FROM Auction A [ROWS UNBOUNDED], Person P [ROWS UNBOUNDED] + WHERE A.seller = P.id + AND (P.state = `OR' OR P.state = `ID' OR P.state = `CA') + AND A.category = 10; + +We'll implement this query to allow 'new auction' events to come before the +'new person' events for the auction seller. Those auctions will be stored until +the matching person is seen. Then all subsequent auctions for a person will use +the stored person record. +""" + +from __future__ import absolute_import + +import logging + +import apache_beam as beam +from apache_beam.coders import coders +from apache_beam.testing.benchmarks.nexmark.models import name_city_state_id +from apache_beam.testing.benchmarks.nexmark.models import nexmark_model +from apache_beam.testing.benchmarks.nexmark.queries import nexmark_query_util +from apache_beam.transforms import trigger +from apache_beam.transforms import userstate +from apache_beam.transforms import window +from apache_beam.transforms.userstate import on_timer +from apache_beam.utils.timestamp import Duration + + +def load(events, metadata=None): + num_events_in_pane = 30 + windowed_events = ( + events + | beam.WindowInto( + window.GlobalWindows(), + trigger=trigger.Repeatedly(trigger.AfterCount(num_events_in_pane)), + accumulation_mode=trigger.AccumulationMode.DISCARDING, + allowed_lateness=Duration.of(0))) Review comment: Done. ########## File path: sdks/python/apache_beam/testing/benchmarks/nexmark/queries/query6.py ########## @@ -0,0 +1,93 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +""" +Query 6, 'Average Selling Price by Seller'. Select the average selling price +over the last 10 closed auctions by the same seller. In CQL syntax:: + + SELECT Istream(AVG(Q.final), Q.seller) + FROM (SELECT Rstream(MAX(B.price) AS final, A.seller) + FROM Auction A [ROWS UNBOUNDED], Bid B [ROWS UNBOUNDED] + WHERE A.id=B.auction + AND B.datetime < A.expires AND A.expires < CURRENT_TIME + GROUP BY A.id, A.seller) [PARTITION BY A.seller ROWS 10] Q + GROUP BY Q.seller; +""" + +from __future__ import absolute_import +from __future__ import division + +import apache_beam as beam +from apache_beam.testing.benchmarks.nexmark.models import seller_price +from apache_beam.testing.benchmarks.nexmark.queries import nexmark_query_util +from apache_beam.testing.benchmarks.nexmark.queries import winning_bids +from apache_beam.transforms import trigger +from apache_beam.transforms import window + + +def load(events, metadata=None): + # find winning bids for each closed auction + return ( + events + # find winning bids + | beam.Filter(nexmark_query_util.auction_or_bid) + | winning_bids.WinningBids() + # (auction_bids -> (aution.seller, bid) + | beam.Map(lambda auc_bid: (auc_bid.auction.seller, auc_bid.bid)) + # calculate and output mean as data arrives + | beam.WindowInto( + window.GlobalWindows(), + trigger=trigger.Repeatedly(trigger.AfterCount(1)), + accumulation_mode=trigger.AccumulationMode.ACCUMULATING, + allowed_lateness=0) + # | beam.combiners.Count.Globally()) Review comment: Done ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
