Source code for apache_beam.testing.benchmarks.nexmark.queries.nexmark_query_util

#
# 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.
#

"""Utilities for working with NEXmark data stream."""
from __future__ import absolute_import

import apache_beam as beam
from apache_beam.testing.benchmarks.nexmark.models import nexmark_model

AUCTION_TAG = 'auctions'
BID_TAG = 'bids'
PERSON_TAG = 'person'


[docs]class ResultNames: SELLER = 'seller' PRICE = 'price' NAME = 'name' CITY = 'city' STATE = 'state' AUCTION_ID = 'auction_id' ID = 'id' RESERVE = 'reserve' CATEGORY = 'category' IS_LAST = 'is_last' BIDDER_ID = 'bidder_id' BID_COUNT = 'bid_count' NUM = 'num'
[docs]def is_bid(event): return isinstance(event, nexmark_model.Bid)
[docs]def is_auction(event): return isinstance(event, nexmark_model.Auction)
[docs]def is_person(event): return isinstance(event, nexmark_model.Person)
[docs]def auction_or_bid(event): return isinstance(event, (nexmark_model.Auction, nexmark_model.Bid))
[docs]class JustBids(beam.PTransform):
[docs] def expand(self, pcoll): return pcoll | "IsBid" >> beam.Filter(is_bid)
[docs]class JustAuctions(beam.PTransform):
[docs] def expand(self, pcoll): return pcoll | "IsAuction" >> beam.Filter(is_auction)
[docs]class JustPerson(beam.PTransform):
[docs] def expand(self, pcoll): return pcoll | "IsPerson" >> beam.Filter(is_person)
[docs]class AuctionByIdFn(beam.DoFn):
[docs] def process(self, element): yield element.id, element
[docs]class BidByAuctionIdFn(beam.DoFn):
[docs] def process(self, element): yield element.auction, element
[docs]class PersonByIdFn(beam.DoFn):
[docs] def process(self, element): yield element.id, element
[docs]class AuctionBySellerFn(beam.DoFn):
[docs] def process(self, element): yield element.seller, element