get-started.td 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. $ set-arg-default default-replica-size=1
  10. $ set-arg-default single-replica-cluster=quickstart
  11. # This test verifies the get started page works.
  12. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  13. ALTER SYSTEM SET enable_create_table_from_source = true
  14. > SET cluster TO ${arg.single-replica-cluster}
  15. > CREATE SOURCE demo
  16. FROM LOAD GENERATOR AUCTION (TICK INTERVAL '50ms', UP TO 1000)
  17. > CREATE TABLE accounts FROM SOURCE demo (REFERENCE accounts);
  18. > CREATE TABLE auctions FROM SOURCE demo (REFERENCE auctions);
  19. > CREATE TABLE bids FROM SOURCE demo (REFERENCE bids);
  20. > CREATE TABLE organizations FROM SOURCE demo (REFERENCE organizations);
  21. > CREATE TABLE users FROM SOURCE demo (REFERENCE users);
  22. > SHOW SOURCES
  23. name type cluster comment
  24. -------------------------------------------------------------------
  25. demo load-generator ${arg.single-replica-cluster} ""
  26. demo_progress progress <null> ""
  27. > SHOW TABLES
  28. name comment
  29. -----------------------
  30. accounts ""
  31. auctions ""
  32. bids ""
  33. organizations ""
  34. users ""
  35. > SHOW COLUMNS FROM auctions
  36. end_time false "timestamp with time zone" ""
  37. id false bigint ""
  38. item false text ""
  39. seller false bigint ""
  40. > SHOW COLUMNS FROM bids
  41. amount false integer ""
  42. auction_id false bigint ""
  43. bid_time false "timestamp with time zone" ""
  44. buyer false bigint ""
  45. id false bigint ""
  46. > CREATE VIEW on_time_bids AS
  47. SELECT
  48. bids.id AS bid_id,
  49. auctions.id AS auction_id,
  50. auctions.item,
  51. bids.bid_time,
  52. auctions.end_time,
  53. bids.amount
  54. FROM bids
  55. JOIN auctions ON bids.auction_id = auctions.id
  56. WHERE bids.bid_time < auctions.end_time
  57. > CREATE MATERIALIZED VIEW avg_bids AS
  58. SELECT auction_id, avg(amount) AS amount
  59. FROM on_time_bids
  60. GROUP BY auction_id
  61. > SELECT auction_id, MAX(amount)
  62. FROM on_time_bids
  63. GROUP BY auction_id
  64. ORDER BY auction_id LIMIT 5
  65. 1 97
  66. 2 44
  67. 3 67
  68. 4 96
  69. 5 95
  70. > CREATE VIEW highest_bid_per_auction AS
  71. SELECT grp.auction_id, bid_id, item, amount, end_time FROM
  72. (SELECT DISTINCT auction_id FROM on_time_bids) grp,
  73. LATERAL (
  74. SELECT * FROM on_time_bids
  75. WHERE auction_id = grp.auction_id
  76. ORDER BY amount DESC LIMIT 1
  77. )
  78. > CREATE MATERIALIZED VIEW winning_bids AS
  79. SELECT * FROM highest_bid_per_auction WHERE end_time < mz_now()
  80. > SELECT auction_id, bid_id, item, amount FROM winning_bids ORDER BY auction_id LIMIT 5
  81. 1 12 "Best Pizza in Town" 97
  82. 2 20 "Custom Art" 44
  83. 3 31 "City Bar Crawl" 67
  84. 4 44 "Best Pizza in Town" 96
  85. 5 54 "Signed Memorabilia" 95
  86. # Shut down the source so it doesn't keep running until next testdrive reset.
  87. > DROP SOURCE demo CASCADE