diff --git a/.github/workflows/prestocpp-linux-build-and-unit-test.yml b/.github/workflows/prestocpp-linux-build-and-unit-test.yml index b60fc65ae732d..943fdec24c712 100644 --- a/.github/workflows/prestocpp-linux-build-and-unit-test.yml +++ b/.github/workflows/prestocpp-linux-build-and-unit-test.yml @@ -16,7 +16,7 @@ jobs: prestocpp-linux-build-for-test: runs-on: ubuntu-22.04 container: - image: prestodb/presto-native-dependency:0.290-20241014120930-e1fc090 + image: ghcr.io/pdabre12/tpcds-connector-test:v1.0 env: CCACHE_DIR: "${{ github.workspace }}/ccache" steps: @@ -58,6 +58,7 @@ jobs: -DPRESTO_ENABLE_PARQUET=ON \ -DPRESTO_ENABLE_REMOTE_FUNCTIONS=ON \ -DPRESTO_ENABLE_JWT=ON \ + -DPRESTO_ENABLE_TPCDS_CONNECTOR=ON \ -DPRESTO_STATS_REPORTER_TYPE=PROMETHEUS \ -DPRESTO_MEMORY_CHECKER_TYPE=LINUX_MEMORY_CHECKER \ -DCMAKE_PREFIX_PATH=/usr/local \ diff --git a/presto-docs/src/main/sphinx/presto-cpp.rst b/presto-docs/src/main/sphinx/presto-cpp.rst index 894fab1767f34..99dc73e1bd2be 100644 --- a/presto-docs/src/main/sphinx/presto-cpp.rst +++ b/presto-docs/src/main/sphinx/presto-cpp.rst @@ -54,4 +54,6 @@ Only specific connectors are supported in the Presto C++ evaluation engine. * Iceberg connector supports both V1 and V2 tables, including tables with delete files. -* TPCH connector, with ``tpch.naming=standard`` catalog property. \ No newline at end of file +* TPCH connector, with ``tpch.naming=standard`` catalog property. + +* TPCDS connector. \ No newline at end of file diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/HiveQueryRunner.java b/presto-hive/src/test/java/com/facebook/presto/hive/HiveQueryRunner.java index 8cf90df570ccb..0b336f738b337 100644 --- a/presto-hive/src/test/java/com/facebook/presto/hive/HiveQueryRunner.java +++ b/presto-hive/src/test/java/com/facebook/presto/hive/HiveQueryRunner.java @@ -211,7 +211,10 @@ public static DistributedQueryRunner createQueryRunner( queryRunner.installPlugin(new TpcdsPlugin()); queryRunner.installPlugin(new TestingHiveEventListenerPlugin()); queryRunner.createCatalog("tpch", "tpch"); - queryRunner.createCatalog("tpcds", "tpcds"); + Map tpcdsProperties = ImmutableMap.builder() + .put("tpcds.use-varchar-type", "true") + .build(); + queryRunner.createCatalog("tpcds", "tpcds", tpcdsProperties); Map tpchProperties = ImmutableMap.builder() .put("tpch.column-naming", "standard") .build(); diff --git a/presto-native-execution/CMakeLists.txt b/presto-native-execution/CMakeLists.txt index d5001dde70a74..803dd2b66e816 100644 --- a/presto-native-execution/CMakeLists.txt +++ b/presto-native-execution/CMakeLists.txt @@ -63,6 +63,8 @@ option(PRESTO_ENABLE_TESTING "Enable tests" ON) option(PRESTO_ENABLE_JWT "Enable JWT (JSON Web Token) authentication" OFF) +option(PRESTO_ENABLE_TPCDS_CONNECTOR "Enable TPC-DS connector" OFF) + # Set all Velox options below add_compile_definitions(FOLLY_HAVE_INT128_T=1) @@ -219,6 +221,10 @@ if(PRESTO_ENABLE_JWT) add_compile_definitions(PRESTO_ENABLE_JWT) endif() +if(PRESTO_ENABLE_TPCDS_CONNECTOR) + add_compile_definitions(PRESTO_ENABLE_TPCDS_CONNECTOR) +endif() + if("${MAX_LINK_JOBS}") set_property(GLOBAL APPEND PROPERTY JOB_POOLS "presto_link_job_pool=${MAX_LINK_JOBS}") diff --git a/presto-native-execution/Makefile b/presto-native-execution/Makefile index f3fb5f709f4d5..57e5cc1d50d6b 100644 --- a/presto-native-execution/Makefile +++ b/presto-native-execution/Makefile @@ -39,6 +39,9 @@ endif ifeq ($(PRESTO_ENABLE_JWT), ON) EXTRA_CMAKE_FLAGS += -DPRESTO_ENABLE_JWT=ON endif +ifeq ($(PRESTO_ENABLE_TPCDS_CONNECTOR), ON) + EXTRA_CMAKE_FLAGS += -PRESTO_ENABLE_TPCDS_CONNECTOR=ON +endif ifneq ($(PRESTO_STATS_REPORTER_TYPE),) EXTRA_CMAKE_FLAGS += -DPRESTO_STATS_REPORTER_TYPE=$(PRESTO_STATS_REPORTER_TYPE) endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/LICENSE b/presto-native-execution/presto_cpp/external/dsdgen/LICENSE new file mode 100644 index 0000000000000..92af24a54f553 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/LICENSE @@ -0,0 +1,320 @@ +END USER LICENSE AGREEMENT +VERSION 2.2 + +READ THE TERMS AND CONDITIONS OF THIS AGREEMENT ("AGREEMENT") CAREFULLY +BEFORE INSTALLING OR USING THE ACCOMPANYING SOFTWARE. BY INSTALLING OR +USING THE SOFTWARE OR RELATED DOCUMENTATION, YOU AGREE TO BE BOUND BY +THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THE TERMS OF THIS +AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. IF YOU ARE ACCESSING THE +SOFTWARE ON BEHALF OF YOUR ORGANIZATION, YOU REPRESENT AND WARRANT THAT +YOU HAVE SUFFICIENT AUTHORITY TO BIND YOUR ORGANIZATION TO THIS +AGREEMENT. + +USE AND RE-EXPORT OF THE SOFTWARE IS SUBJECT TO THE UNITED STATES EXPORT +CONTROL ADMINISTRATION REGULATIONS. THE SOFTWARE MAY NOT BE USED BY +UNLICENSED PERSONS OR ENTITIES, AND MAY NOT BE RE- EXPORTED TO ANOTHER +COUNTRY. SEE EXPORT ASSURANCE (CLAUSE 13) OF THIS LICENSE. + +This is a legal agreement between you (or, if you are accessing the +software on behalf of your organization, your organization) ("You" or +"User") and the Transaction Processing Performance Council ("TPC"). This +Agreement states the terms and conditions upon which TPC offers to +license the Software, including, but not limited to, the source code, +scripts, executable programs, drivers, libraries and data files +associated with such programs, and modifications thereof (the +"Software"), and online, electronic or printed documentation +("Documentation," together with the Software, "Materials"). + +LICENSE + +1. Definitions + +"Executive Summary" shall mean a short summary of a TPC Benchmark Result +that shows the configuration, primary metrics, performance data, and +pricing details. The exact requirements for the Executive Summary are +defined in each TPC Benchmark Standard. +"Full Disclosure Report (FDR)" shall mean a document that describes The +TPC Benchmark Result in sufficient detail such that the Result could be +recreated. The exact requirements for the FDR are defined in each TPC +Benchmark Standard. +"TPC Benchmark Result (Result)" shall mean a performance test submitted +to the TPC attested to meet the requirements of a TPC Benchmark Standard +at the time of submission. A Result is documented by an Executive +Summary and, if required, a FDR. +"TPC Benchmark Standard" shall mean a TPC Benchmark Specification and +any associated code or binaries approved by the TPC. The various TPC +Benchmark Standards can be found at +http://www.tpc.org/information/current_specifications.asp. +"TPC Policies" shall mean the guiding principles for how the TPC +conducts its operations and business. The current TPC Policies can be +found at http://www.tpc.org/information/current_specifications.asp. + +2. Ownership. The Materials are licensed, not sold, to You for use only +under the terms of this Agreement. As between You and TPC (and, to the +extent applicable, its licensors), TPC retains all rights, title and +interest to and ownership of the Materials and reserves all rights not +expressly granted to You. + +3. License Grant. Subject to Your compliance in all material respects +with the terms and conditions of this Agreement, TPC grants You a +restricted, non-exclusive, revocable license to install and use the +Materials, but only as expressly permitted herein. You may only use the +Software on computer systems under Your direct control. You may download +multiple copies of the Materials and make verbatim copies of the +original of the Software so long as Your use of such copies complies +with the terms of this Agreement. +a. Use by Individual. If You are accessing the Materials as an +individual, only You (as an individual) may access and use the +Materials. +b. Use by Organization. If You are accessing the Materials on behalf of +Your organization, only You and those within Your organization may use +the Materials. Your organization must identify a contact person to TPC +and conduct communications with TPC through that contact person. + +4. Restrictions. The following restrictions apply to all use of the +Materials by You. +a. General: You may not: +(1) use, copy, print, modify, adapt, create derivative works from, +market, deliver, rent, lease, sublicense, make, have made, assign, +pledge, transfer, sell, offer to sell, import, reproduce, distribute, +publicly perform, publicly display or otherwise grant rights to the +Materials, or any copy thereof, in whole or in part, except as expressly +permitted under this Agreement; or +(2) use the Materials in any way that does not comply with all +applicable laws and regulations. +b. Modification: You may modify the Software. +c. Public Disclosure: You may not publicly disclose any performance +results produced while using the Software except in the following +circumstances: +(1) as part of a TPC Benchmark Result. For purposes of this Agreement, a +"TPC Benchmark Result" is a performance test submitted to the TPC, +documented by a Full Disclosure Report and Executive Summary, claiming +to meet the requirements of an official TPC Benchmark Standard. You +agree that TPC Benchmark Results may only be published in accordance +with the TPC Policies. viewable at http: //www.tpc.org +(2) as part of an academic or research effort that does not imply or +state a marketing position +(3) any other use of the Software, provided that any performance results +must be clearly identified as not being comparable to TPC Benchmark +Results unless specifically authorized by TPC. + +5. License Modification. Requests for modification of this license shall +be addressed to info@tpc.org. You may not remove or modify this license +without permission. + +6. Copyright. The Materials are owned by TPC and/or its licensors, and +are protected by United States copyright laws and international treaty +provisions. You may not remove the copyright notice from the original or +any copy of the Materials, and You must apply the notice if You extract +part of the Materials not bearing a notice. + +7. Use of Name. You acknowledge and agree that TPC owns all trademark +and trade name rights in the names, trademarks and logos used by TPC in +the Materials. User shall preserve any notices regarding such ownership. +User may only use such names, trademarks and logos in accordance with +the usage guidelines specified by the TPC Policies. + +8. Merger or Integration. Any portion of the Materials merged into or +integrated with other software or documentation will continue to be +subject to the terms and conditions of this Agreement. + +9. Limited Grants of Sublicense. You may distribute the Software as +provided or as modified as permitted under clause 4 b. of this +Agreement, provided You comply with all of the terms of this Agreement +and the following conditions: + +a. If You distribute any portion of the Software in its original form +You may do so only under this Agreement by including a complete copy of +this Agreement with Your distribution, and if You distribute the +Software in modified form, You may only do so under a license that at a +minimum provides all of the protections and conditions of use contained +within this Agreement; + +b. You must include on each copy of the Software that You distribute the +following legend in all caps, at the top of the label and license, and +in a font not less than 12 point and no less prominent than any other +printing: "THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC."; + +c. You must retain all copyright, patent, trademark, and attribution +notices that are present in the Software; and + +d. You may not charge a fee for the distribution of this Software, +including any modifications permitted under clause 4.b. + +10. Term and Termination. +a. Term. The license granted to You is effective until terminated. +b. Termination. +(1) By You. You may terminate this Agreement at any time by returning +the Materials (including any portions or copies thereof) to TPC or +providing written notice to the TPC that all copies of the Materials +within Your custody or control have been deleted or destroyed. +(2) By TPC. In the event You materially fail to comply with any term or +condition of this Agreement, and You fail to remedy such non-compliance +within 30 days after the receipt of notice to that effect, then TPC +shall have the right to terminate this Agreement immediately upon +written notice at the end of such 30-day period. +c. Effect of Termination. Termination of this Agreement in accordance +with this clause 10 will not terminate the rights of end users +sublicensed by You pursuant to this Agreement. Moreover, upon +termination and at TPC's written request, You agree to either (1) return +the Materials (including any portions or copies thereof) to TPC or (2) +immediately destroy all copies of the Materials within Your custody or +control and inform the TPC of the destruction of the Materials. Upon +termination, TPC may also enforce any rights provided by law. The +provisions of this Agreement that protect the proprietary rights of TPC +and its Licensors will continue in force after termination. + +11. No Warranty; Materials Provided "As Is". TO THE MAXIMUM EXTENT +PERMITTED BY APPLICABLE LAW, THE MATERIALS ARE PROVIDED "AS IS" AND WITH +ALL FAULTS, AND TPC (AND ITS LICENSORS) AND THE AUTHORS AND DEVELOPERS +OF THE MATERIALS HEREBY DISCLAIM ALL WARRANTIES, REPRESENTATIONS AND +CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT +LIMITED TO, ANY IMPLIED WARRANTIES, DUTIES OR CONDITIONS RELATING TO +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR +COMPLETENESS OF RESPONSES, RESULTS, WORKMANLIKE EFFORT, LACK OF VIRUSES, +LACK OF NEGLIGENCE, TITLE, QUIET ENJOYMENT, QUIET POSSESSION, +CORRESPONDENCE TO DESCRIPTION OR NONINFRINGEMENT. USER RECOGNIZES THAT +THE MATERIALS ARE THE RESULT OF A COOPERATIVE, NON-PROFIT EFFORT AND +THAT TPC DOES NOT CONDUCT A TYPICAL BUSINESS. USER ACCEPTS THE MATERIALS +"AS IS" AND WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. + +Without limitation, TPC (and its licensors) do not warrant that the +functions contained in the Software or Materials will meet Your +requirements or that the operation of the Software will be +uninterrupted, error-free or free from malicious code. For purposes of +this paragraph, "malicious code" means any program code designed to +contaminate other computer programs or computer data, consume computer +resources, modify, destroy, record, or transmit data, or in some other +fashion usurp the normal operation of the computer, computer system, or +computer network, including viruses, Trojan horses, droppers, worms, +logic bombs, and the like. TPC (and its licensors) shall not be liable +for the accuracy of any information provided by TPC or third-party +technical support personnel, or any damages caused, either directly or +indirectly, by acts taken or omissions made by You as a result of such +technical support. + +You assume full responsibility for the selection of the Materials to +achieve Your intended results, and for the installation, use and results +obtained from the Materials. You also assume the entire risk as it +applies to the quality and performance of the Materials. Should the +Materials prove defective, You (and not TPC) assume the entire liability +of any and all necessary servicing, repair or correction. Some +countries/states do not allow the exclusion of implied warranties, so +the above exclusion may not apply to You. TPC (and its licensors) +further disclaims all warranties of any kind if the Materials were +customized, repackaged or altered in any way by any party other than TPC +(or its licensors). + +12. Disclaimer of Liability. TPC (and its licensors) assumes no +liability with respect to the Materials, including liability for +infringement of intellectual property rights, negligence, or any other +liability. TPC is not aware of any infringement of copyright or patent +that may result from its grant of rights to User of the Materials. If +User receives any notice of infringement, such notice shall be +immediately communicated to TPC who will have sole discretion to take +action to evaluate the claim and, if practicable, modify the Materials +as necessary to avoid infringement. In the event that TPC determines +that the Materials cannot be modified to avoid such infringement (or any +other infringement claim communicated to TPC), TPC may terminate this +Agreement immediately. User shall suspend use of the Materials until +modifications to avoid claims of infringement have been completed. User +waives any claim against TPC in the event of such infringement claims by +others. + +13. Export Assurance. Use and re-export of the Materials and related +technical information is subject to the Export Administration +Regulations (EAR) of the United States Department of Commerce. User +hereby agrees that User (a) assumes responsibility for compliance with +the EAR in its use of the Materials and technical information, and (b) +will not export, re-export, or otherwise disclose directly or +indirectly, the Materials, technical data, or any direct product of the +Materials or technical data in violation of the EAR. + +14. Limitation of Remedies And Damages. IN NO EVENT WILL TPC OR ITS +LICENSORS OR LICENSEE BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL OR +CONSEQUENTIAL DAMAGES OR FOR ANY LOST PROFITS, LOST SAVINGS, LOST +REVENUES OR LOST DATA ARISING FROM OR RELATING TO THE MATERIALS OR THIS +AGREEMENT, EVEN IF TPC OR ITS LICENSORS OR LICENSEE HAVE BEEN ADVISED OF +THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL TPC'S OR ITS +LICENSORS' LIABILITY OR DAMAGES TO YOU OR ANY OTHER PERSON EVER EXCEED +U.S. ONE HUNDRED DOLLARS (US $100), REGARDLESS OF THE FORM OF THE CLAIM. +IN NO EVENT WILL LICENSEE'S LIABILITY OR DAMAGES TO TPC OR ANY OTHER +PERSON EVER EXCEED $1,000,000, REGARDLESS OF THE FORM OF THE CLAIM. Some +countries/states do not allow the limitation or exclusion of liability +for incidental or consequential damages, so the above limitation or +exclusion may not apply to You. + +15. U.S. Government Restricted Rights. All Software and related +documentation are provided with restricted rights. Use, duplication or +disclosure by the U.S. Government is subject to restrictions as set +forth in subdivision (b)(3)(ii) of the Rights in Technical Data and +Computer Software Clause at 252.227-7013. If You are using the Software +outside of the United States, You will comply with the applicable local +laws of Your country, U.S. export control law, and the English version +of this Agreement. + +16. Contractor/Manufacturer. The Contractor/Manufacturer for the +Software is: + +Transaction Processing Performance Council +572B Ruger Street, P.O. Box 29920 +San Francisco, CA 94129 + +17. General. This Agreement is binding on You as well as Your employees, +employers, contractors and agents, and on any successors and assignees. +This Agreement is governed by the laws of the State of California +(except to the extent federal law governs copyrights and trademarks) +without respect to any provisions of California law that would cause +application of the law of another state or country. The parties agree +that the United Nations Convention on Contracts for the International +Sale of Goods will not govern this Agreement. This Agreement is the +entire agreement between us regarding the subject matter hereof and +supersedes any other understandings or agreements with respect to the +Materials or the subject matter hereof. If any provision of this +Agreement is deemed invalid or unenforceable by any court having +jurisdiction, that particular provision will be deemed modified to the +extent necessary to make the provision valid and enforceable, and the +remaining provisions will remain in full force and effect. + +SPECIAL PROVISIONS APPLICABLE TO THE EUROPEAN UNION + +If You acquired the Materials in the European Union (EU), the following +provisions also apply to You. If there is any inconsistency between the +terms of the Software License Agreement set out earlier and the +following provisions, the following provisions shall take precedence. + +1. Distribution. You may sublicense modifications of the Software +covered in this Agreement if they meet the requirements of clause 9 +above. + +2. Limited Warranty. EXCEPT AS STATED EARLIER IN THIS AGREEMENT, AND AS +PROVIDED UNDER THE HEADING "STATUTORY RIGHTS", THE SOFTWARE IS PROVIDED +AS-IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, +INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES, NONINFRINGEMENT, +OR CONDITIONS OF MERCHANTABILITY, QUALITY AND FITNESS FOR A PARTICULAR +PURPOSE. + +3. Limitation of Remedy and Damages. THE LIMITATIONS OF REMEDIES AND +DAMAGES IN THE SOFTWARE LICENSE AGREEMENT SHALL NOT APPLY TO PERSONAL +INJURY (INCLUDING DEATH) TO ANY PERSON CAUSED BY TPC'S NEGLIGENCE AND +ARE SUBJECT TO THE PROVISION SET OUT UNDER THE HEADING "STATUTORY +RIGHTS". + +4. Statutory Rights: Irish law provides that certain conditions and +warranties may be implied in contracts for the sale of goods and in +contracts for the supply of services. Such conditions and warranties are +hereby excluded, to the extent such exclusion, in the context of this +transaction, is lawful under Irish law. Conversely, such conditions and +warranties, insofar as they may not be lawfully excluded, shall apply. +Accordingly nothing in this Agreement shall prejudice any rights that +You may enjoy by virtue of Sections 12, 13, 14 or 15 of the Irish Sale +of Goods Act 1893 (as amended). + +5. General. This Agreement is governed by the laws of the Republic of +Ireland. The local language version of this agreement shall apply to +Materials acquired in the EU. This Agreement is the entire agreement +between us with respect to the subject matter hereof and You agree that +TPC will not have any liability for any untrue statement or +representation made by it, its agents or anyone else (whether innocently +or negligently) upon which You relied upon entering this Agreement, +unless such untrue statement or representation was made fraudulently. \ No newline at end of file diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/CMakeLists.txt b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/CMakeLists.txt new file mode 100644 index 0000000000000..73c88cda44daf --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/CMakeLists.txt @@ -0,0 +1,66 @@ +# +# Copyright owned by the Transaction Processing Performance Council. +# +# A copy of the license is included under external/dsdgen/LICENSE +# in this repository. +# +# You may not use this file except in compliance with the License. +# +# THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. +# + +add_library( + dsdgen_c OBJECT + skip_days.cpp + address.cpp + build_support.cpp + date.cpp + dbgen_version.cpp + decimal.cpp + dist.cpp + error_msg.cpp + genrand.cpp + join.cpp + list.cpp + load.cpp + misc.cpp + nulls.cpp + parallel.cpp + permute.cpp + pricing.cpp + r_params.cpp + scaling.cpp + scd.cpp + sparse.cpp + StringBuffer.cpp + tdef_functions.cpp + tdefs.cpp + text.cpp + w_call_center.cpp + w_catalog_page.cpp + w_catalog_returns.cpp + w_catalog_sales.cpp + w_customer.cpp + w_customer_address.cpp + w_customer_demographics.cpp + w_datetbl.cpp + w_household_demographics.cpp + w_income_band.cpp + w_inventory.cpp + w_item.cpp + w_promotion.cpp + w_reason.cpp + w_ship_mode.cpp + w_store.cpp + w_store_returns.cpp + w_store_sales.cpp + w_timetbl.cpp + w_warehouse.cpp + w_web_page.cpp + w_web_returns.cpp + w_web_sales.cpp + w_web_site.cpp) + +include_directories(${CMAKE_SOURCE_DIR}/presto_cpp/external/dsdgen/include) +include_directories( + ${CMAKE_SOURCE_DIR}/presto_cpp/external/dsdgen/include/dsdgen-c) diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/StringBuffer.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/StringBuffer.cpp new file mode 100644 index 0000000000000..f2ca1f0fda685 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/StringBuffer.cpp @@ -0,0 +1,158 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include +#include +#include "config.h" +#include "porting.h" +#ifndef USE_STDLIB_H +#include +#endif +#include "StringBuffer.h" + +/* + * Routine: InitBuffer + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +StringBuffer_t* InitBuffer(int nSize, int nIncrement) { + StringBuffer_t* pBuf = nullptr; + + pBuf = static_cast(malloc(sizeof(struct STRING_BUFFER_T))); + MALLOC_CHECK(pBuf); + if (pBuf == NULL) + return (NULL); + memset(static_cast(pBuf), 0, sizeof(struct STRING_BUFFER_T)); + + pBuf->pText = static_cast(malloc(sizeof(char) * nSize)); + MALLOC_CHECK(pBuf->pText); + if (pBuf->pText == NULL) + return (NULL); + memset(static_cast(pBuf->pText), 0, sizeof(char) * nSize); + + pBuf->nIncrement = nIncrement; + pBuf->nBytesAllocated = nSize; + pBuf->nFlags = SB_INIT; + + return (pBuf); +} + +/* + * Routine: AddBuffer + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int AddBuffer(StringBuffer_t* pBuf, char* pStr) { + int nRemaining = pBuf->nBytesAllocated - pBuf->nBytesUsed, + nRequested = strlen(pStr); + + if (!nRequested) + return (0); + + while (nRequested >= nRemaining) { + pBuf->pText = static_cast(realloc( + static_cast(pBuf->pText), + pBuf->nBytesAllocated + pBuf->nIncrement)); + if (!pBuf->pText) + return (-1); + pBuf->nBytesAllocated += pBuf->nIncrement; + nRemaining += pBuf->nIncrement; + } + + strncat(pBuf->pText, pStr, pBuf->nBytesAllocated); + if (pBuf->nBytesUsed == 0) /* first string adds a terminator */ + pBuf->nBytesUsed = 1; + pBuf->nBytesUsed += nRequested; + + return (0); +} + +/* + * Routine: ResetStringBuffer + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int ResetBuffer(StringBuffer_t* pBuf) { + pBuf->nBytesUsed = 0; + if (pBuf->nBytesAllocated) + pBuf->pText[0] = '\0'; + + return (0); +} + +/* + * Routine: GetBuffer + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +char* GetBuffer(StringBuffer_t* pBuf) { + return (pBuf->pText); +} + +/* + * Routine: FreeBuffer + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void FreeBuffer(StringBuffer_t* pBuf) { + if (!pBuf) + return; + if (pBuf->pText) + free(static_cast(pBuf->pText)); + free(static_cast(pBuf)); + + return; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/address.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/address.cpp new file mode 100644 index 0000000000000..60b6df1540326 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/address.cpp @@ -0,0 +1,360 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "address.h" +#include +#include "columns.h" +#include "config.h" +#include "dist.h" +#include "genrand.h" +#include "permute.h" +#include "porting.h" +#include "r_params.h" +#include "scaling.h" +#include "tables.h" +#include "tdefs.h" + +static int s_nCountyCount = 0; +static int s_nCityCount = 0; + +void resetCountCount(void) { + s_nCountyCount = 0; + s_nCityCount = 0; + + return; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int mk_address(ds_addr_t* pAddr, int nColumn, DSDGenContext& dsdGenContext) { + int i = 0, nRegion = 0; + char *szZipPrefix = nullptr, szAddr[100]; + int nMaxCities, nMaxCounties; + tdef* pTdef; + + nMaxCities = static_cast(get_rowcount(ACTIVE_CITIES, dsdGenContext)); + nMaxCounties = static_cast(get_rowcount(ACTIVE_COUNTIES, dsdGenContext)); + + /* street_number is [1..1000] */ + genrand_integer( + &pAddr->street_num, DIST_UNIFORM, 1, 1000, 0, nColumn, dsdGenContext); + + /* street names are picked from a distribution */ + pick_distribution( + &pAddr->street_name1, "street_names", 1, 1, nColumn, dsdGenContext); + pick_distribution( + &pAddr->street_name2, "street_names", 1, 2, nColumn, dsdGenContext); + + /* street type is picked from a distribution */ + pick_distribution( + &pAddr->street_type, "street_type", 1, 1, nColumn, dsdGenContext); + + /* suite number is alphabetic 50% of the time */ + genrand_integer(&i, DIST_UNIFORM, 1, 100, 0, nColumn, dsdGenContext); + if (i & 0x01) { + auto result = sprintf(pAddr->suite_num, "Suite %d", (i >> 1) * 10); + if (result < 0) + perror("sprintf failed"); + } else { + auto result = sprintf(pAddr->suite_num, "Suite %c", ((i >> 1) % 25) + 'A'); + if (result < 0) + perror("sprintf failed"); + } + + pTdef = getTdefsByNumber( + getTableFromColumn(nColumn, dsdGenContext), dsdGenContext); + + /* city is picked from a distribution which maps to large/medium/small */ + if (pTdef->flags & FL_SMALL) { + i = static_cast(get_rowcount( + getTableFromColumn(nColumn, dsdGenContext), dsdGenContext)); + genrand_integer( + &i, + DIST_UNIFORM, + 1, + (nMaxCities > i) ? i : nMaxCities, + 0, + nColumn, + dsdGenContext); + dist_member(&pAddr->city, "cities", i, 1, dsdGenContext); + } else + pick_distribution(&pAddr->city, "cities", 1, 6, nColumn, dsdGenContext); + + /* county is picked from a distribution, based on population and keys the + * rest */ + if (pTdef->flags & FL_SMALL) { + i = (int)get_rowcount( + getTableFromColumn(nColumn, dsdGenContext), dsdGenContext); + genrand_integer( + &nRegion, + DIST_UNIFORM, + 1, + (nMaxCounties > i) ? i : nMaxCounties, + 0, + nColumn, + dsdGenContext); + dist_member(&pAddr->county, "fips_county", nRegion, 2, dsdGenContext); + } else + nRegion = pick_distribution( + &pAddr->county, "fips_county", 2, 1, nColumn, dsdGenContext); + + /* match state with the selected region/county */ + dist_member(&pAddr->state, "fips_county", nRegion, 3, dsdGenContext); + + /* match the zip prefix with the selected region/county */ + pAddr->zip = city_hash(0, pAddr->city); + /* 00000 - 00600 are unused. Avoid them */ + dist_member( + static_cast(&szZipPrefix), + "fips_county", + nRegion, + 5, + dsdGenContext); + if (!(szZipPrefix[0] - '0') && (pAddr->zip < 9400)) + pAddr->zip += 600; + pAddr->zip += (szZipPrefix[0] - '0') * 10000; + + auto result = sprintf( + szAddr, + "%d %s %s %s", + pAddr->street_num, + pAddr->street_name1, + pAddr->street_name2, + pAddr->street_type); + if (result < 0) + perror("sprintf failed"); + pAddr->plus4 = city_hash(0, szAddr); + dist_member(&pAddr->gmt_offset, "fips_county", nRegion, 6, dsdGenContext); + strcpy(pAddr->country, "United States"); + + return (0); +} + +/* + * Routine: mk_streetnumber + * Purpose: + * one of a set of routines that creates addresses + * Algorithm: + * Data Structures: + * + * Params: + * nTable: target table (and, by extension, address) to allow differing + *distributions dest: destination for the random number Returns: Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: 20030422 jms should be replaced if there is no table variation + */ +int mk_streetnumber(int nTable, int* dest, DSDGenContext& dsdGenContext) { + genrand_integer(dest, DIST_UNIFORM, 1, 1000, 0, nTable, dsdGenContext); + + return (0); +} + +/* + * Routine: mk_suitenumber() + * Purpose: + * one of a set of routines that creates addresses + * Algorithm: + * Data Structures: + * + * Params: + * nTable: target table (and, by extension, address) to allow differing + *distributions dest: destination for the random number Returns: Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: 20010615 JMS return code is meaningless + */ +int mk_suitenumber(int nTable, char* dest, DSDGenContext& dsdGenContext) { + int i; + + genrand_integer(&i, DIST_UNIFORM, 1, 100, 0, nTable, dsdGenContext); + if (i <= 50) { + genrand_integer(&i, DIST_UNIFORM, 1, 1000, 0, nTable, dsdGenContext); + auto result = sprintf(dest, "Suite %d", i); + if (result < 0) + perror("sprintf failed"); + } else { + genrand_integer(&i, DIST_UNIFORM, 0, 25, 0, nTable, dsdGenContext); + auto result = sprintf(dest, "Suite %c", i + 'A'); + if (result < 0) + perror("sprintf failed"); + } + + return (0); +} + +/* + * Routine: mk_streetname() + * Purpose: + * one of a set of routines that creates addresses + * Algorithm: + * use a staggered distibution and the 150 most common street names in the + *US Data Structures: + * + * Params: + * nTable: target table (and, by extension, address) to allow differing + *distributions dest: destination for the street name Returns: Called By: Calls: + * Assumptions: + * Side Effects: + * TODO: 20010615 JMS return code is meaningless + */ +int mk_streetname(int nTable, char* dest, DSDGenContext& dsdGenContext) { + char *pTemp1 = nullptr, *pTemp2 = nullptr; + + pick_distribution( + static_cast(&pTemp1), + "street_names", + (int)1, + (int)1, + nTable, + dsdGenContext); + pick_distribution( + static_cast(&pTemp2), + "street_names", + (int)1, + (int)2, + nTable, + dsdGenContext); + + if (pTemp1 && pTemp2) { + if (strlen(pTemp2)) { + auto result = sprintf(dest, "%s %s", pTemp1, pTemp2); + if (result < 0) + perror("sprintf failed"); + } else + strcpy(dest, pTemp1); + } + + return (0); +} + +/* + * Routine: mk_city + * Purpose: + * one of a set of routines that creates addresses + * Algorithm: + * use a staggered distibution of 1000 most common place names in the US + * Data Structures: + * + * Params: + * nTable: target table (and, by extension, address) to allow differing + *distributions dest: destination for the city name Returns: Called By: Calls: + * Assumptions: + * Side Effects: + * TODO: 20030423 jms should be replaced if there is no per-table variation + */ +int mk_city(int nTable, char** dest, DSDGenContext& dsdGenContext) { + pick_distribution( + static_cast(dest), + "cities", + static_cast(1), + static_cast(get_int("_SCALE_INDEX", dsdGenContext)), + 11, + dsdGenContext); + + return (0); +} + +/* + * Routine: city_hash() + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int city_hash(int nTable, char* name) { + char* cp; + int hash_value = 0, res = 0; + + for (cp = name; *cp; cp++) { + hash_value *= 26; + hash_value -= 'A'; + hash_value += *cp; + if (hash_value > 1000000) { + hash_value %= 10000; + res += hash_value; + hash_value = 0; + } + } + hash_value %= 1000; + res += hash_value; + res %= 10000; /* looking for a 4 digit result */ + + return (res); +} + +/* + * Routine: + * one of a set of routines that creates addresses + * Algorithm: + * use a compound distribution of the 3500 counties in the US + * Data Structures: + * + * Params: + * nTable: target table (and, by extension, address) to allow differing + *distributions dest: destination for the city name nRegion: the county selected + * city: the city name selected + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: 20010615 JMS return code is meaningless + */ +int mk_zipcode( + int nTable, + char* dest, + int nRegion, + char* city, + DSDGenContext& dsdGenContext) { + char* szZipPrefix = nullptr; + int nCityCode; + int nPlusFour; + + if (szZipPrefix) { + dist_member( + static_cast(&szZipPrefix), + "fips_county", + nRegion, + 5, + dsdGenContext); + nCityCode = city_hash(nTable, city); + genrand_integer( + &nPlusFour, DIST_UNIFORM, 1, 9999, 0, nTable, dsdGenContext); + auto result = + sprintf(dest, "%s%04d-%04d", szZipPrefix, nCityCode, nPlusFour); + if (result < 0) + perror("sprintf failed"); + } + + return (0); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/build_support.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/build_support.cpp new file mode 100644 index 0000000000000..f1191b0d6f5dc --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/build_support.cpp @@ -0,0 +1,442 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include +#include "config.h" +#include "porting.h" +#ifndef WIN32 +#include +#endif +#include +#include "StringBuffer.h" +#include "build_support.h" +#include "columns.h" +#include "constants.h" +#include "decimal.h" +#include "dist.h" +#include "error_msg.h" +#include "genrand.h" +#include "r_params.h" +#include "scaling.h" +#include "tables.h" +#include "tdefs.h" + +/* + * Routine: hierarchy_item + * Purpose: + * select the hierarchy entry for this level + * Algorithm: Assumes a top-down ordering + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ +void hierarchy_item( + int h_level, + ds_key_t* id, + char** name, + ds_key_t kIndex, + DSDGenContext& dsdGenContext) { + static int nLastCategory = -1, nLastClass = -1, nBrandBase; + int nBrandCount = 0; + static char* szClassDistName = nullptr; + + switch (h_level) { + case I_CATEGORY: + nLastCategory = + pick_distribution(name, "categories", 1, 1, h_level, dsdGenContext); + *id = nLastCategory; + nBrandBase = nLastCategory; + nLastClass = -1; + break; + case I_CLASS: + if (nLastCategory == -1) + ReportErrorNoLine( + DBGEN_ERROR_HIERACHY_ORDER, "I_CLASS before I_CATEGORY", 1); + dist_member( + &szClassDistName, "categories", nLastCategory, 2, dsdGenContext); + nLastClass = pick_distribution( + name, szClassDistName, 1, 1, h_level, dsdGenContext); + nLastCategory = -1; + *id = nLastClass; + break; + case I_BRAND: { + if (nLastClass == -1) + ReportErrorNoLine( + DBGEN_ERROR_HIERACHY_ORDER, "I_BRAND before I_CLASS", 1); + dist_member(&nBrandCount, szClassDistName, nLastClass, 2, dsdGenContext); + *id = kIndex % nBrandCount + 1; + mk_word( + *name, + "brand_syllables", + nBrandBase * 10 + nLastClass, + 45, + I_BRAND, + dsdGenContext); + int idValue = static_cast(*id); + char sTemp[6 + std::to_string(idValue).size()]; + auto result = sprintf(sTemp, " #%d", idValue); + if (result < 0) + perror("sprintf failed"); + strcat(*name, sTemp); + *id += (nBrandBase * 1000 + nLastClass) * 1000; + break; + } + default: + auto result = printf( + "ERROR: Invalid call to hierarchy_item with argument '%d'\n", + h_level); + if (result < 0) + perror("sprintf failed"); + exit(1); + } + + return; +} + +/* + * Routine: mk_companyname() + * Purpose: + * yet another member of a set of routines used for address creation + * Algorithm: + * create a hash, based on an index value, so that the same result can be + *derived reliably and then build a word from a syllable set Data Structures: + * + * Params: + * char * dest: target for resulting name + * int nTable: to allow differing distributions + * int nCompany: index value + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20010615 JMS return code is meaningless + * 20030422 JMS should be replaced if there is no per-table variation + */ +int mk_companyname( + char* dest, + int nTable, + int nCompany, + DSDGenContext& dsdGenContext) { + mk_word(dest, "syllables", nCompany, 10, CC_COMPANY_NAME, dsdGenContext); + + return (0); +} + +/* + * Routine: set_locale() + * Purpose: + * generate a reasonable lattitude and longitude based on a region and the + *USGS data on 3500 counties in the US Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: 20011230 JMS set_locale() is just a placeholder; do we need geographic + *coords? + */ +int set_locale(int nRegion, decimal_t* longitude, decimal_t* latitude) { + static int init = 0; + static decimal_t dZero; + + if (!init) { + strtodec(&dZero, "0.00"); + init = 1; + } + + memcpy(longitude, &dZero, sizeof(decimal_t)); + memcpy(latitude, &dZero, sizeof(decimal_t)); + + return (0); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void bitmap_to_dist( + void* pDest, + const char* distname, + ds_key_t* modulus, + int vset, + int stream, + DSDGenContext& dsdGenContext) { + int32_t m, s; + unsigned int len = strlen(distname); + char msg[len + 31]; + + if ((s = distsize(distname, dsdGenContext)) == -1) { + auto result = sprintf(msg, "Invalid distribution name '%s'", distname); + if (result < 0) + perror("sprintf failed"); + INTERNAL(msg); + } + m = static_cast((*modulus % s) + 1); + *modulus /= s; + + dist_member(pDest, distname, m, vset, dsdGenContext); + + return; +} + +/* + * Routine: void dist_to_bitmap(int *pDest, char *szDistName, int nValueSet, int + * nWeightSet, int nStream) Purpose: Reverse engineer a composite key based on + * distributions Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void dist_to_bitmap( + int* pDest, + const char* szDistName, + int nValue, + int nWeight, + int nStream, + DSDGenContext& dsdGenContext) { + *pDest *= distsize(szDistName, dsdGenContext); + *pDest += pick_distribution( + NULL, szDistName, nValue, nWeight, nStream, dsdGenContext); + + return; +} + +/* + * Routine: void random_to_bitmap(int *pDest, int nDist, int nMin, int nMax, int + * nMean, int nStream) Purpose: Reverse engineer a composite key based on an + * integer range Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void random_to_bitmap( + int* pDest, + int nDist, + int nMin, + int nMax, + int nMean, + int nStream, + DSDGenContext& dsdGenContext) { + *pDest *= nMax; + *pDest += + genrand_integer(NULL, nDist, nMin, nMax, nMean, nStream, dsdGenContext); + + return; +} + +/* + * Routine: mk_word() + * Purpose: + * generate a gibberish word from a given syllable set + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ +void mk_word( + char* dest, + const char* syl_set, + ds_key_t src, + int char_cnt, + int col, + DSDGenContext& dsdGenContext) { + ds_key_t i = src, nSyllableCount; + char* cp = nullptr; + + *dest = '\0'; + while (i > 0) { + nSyllableCount = distsize(syl_set, dsdGenContext); + dist_member( + &cp, + syl_set, + static_cast(i % nSyllableCount) + 1, + 1, + dsdGenContext); + i /= nSyllableCount; + if (static_cast(strlen(dest) + strlen(cp)) <= char_cnt) + strcat(dest, cp); + else + break; + } + + return; +} + +/* + * Routine: mk_surrogate() + * Purpose: create a character based surrogate key from a 64-bit value + * Algorithm: since the RNG routines produce a 32bit value, and surrogate keys + *can reach beyond that, use the RNG output to generate the lower end of a + *random string, and build the upper end from a ds_key_t Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: ltoc() + * Assumptions: output is a 16 character string. Space is not checked + * Side Effects: + * TODO: + * 20020830 jms may need to define a 64-bit form of htonl() for portable shift + *operations + */ +void ltoc(char* szDest, unsigned long nVal) { + char szXlate[16] = { + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P'}; + + char c; + for (int i = 0; i < 8; i++) { + c = szXlate[(static_cast(nVal) & 0xF)]; + *szDest++ = c; + nVal >>= 4; + } + *szDest = '\0'; +} + +void mk_bkey(char* szDest, ds_key_t kPrimary, int nStream) { + unsigned long nTemp; + + nTemp = static_cast(kPrimary >> 32); + ltoc(szDest, nTemp); + + nTemp = + static_cast(static_cast(kPrimary) & 0xFFFFFFFF); + ltoc(szDest + 8, nTemp); + + return; +} + +/* + * Routine: embed_string(char *szDest, char *szDist, int nValue, int nWeight, + * int nStream, DSDGenContext& dsdGenContext) Purpose: Algorithm: Data + * Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int embed_string( + char* szDest, + const char* szDist, + int nValue, + int nWeight, + int nStream, + DSDGenContext& dsdGenContext) { + int nPosition = 0; + char* szWord = nullptr; + + pick_distribution(&szWord, szDist, nValue, nWeight, nStream, dsdGenContext); + nPosition = genrand_integer( + NULL, + DIST_UNIFORM, + 0, + strlen(szDest) - strlen(szWord) - 1, + 0, + nStream, + dsdGenContext); + memcpy(&szDest[nPosition], szWord, sizeof(char) * strlen(szWord)); + + return (0); +} + +/* + * Routine: adjust the valid date window for source schema tables, based on + * based on the update count, update window size, etc. + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void setUpdateDateRange( + int nTable, + date_t* pMinDate, + date_t* pMaxDate, + DSDGenContext& dsdGenContext) { + static int nUpdateNumber; + + if (!dsdGenContext.setUpdateDateRange_init) { + nUpdateNumber = get_int("UPDATE", dsdGenContext); + dsdGenContext.setUpdateDateRange_init = 1; + } + + switch (nTable) /* no per-table changes at the moment; but could be */ + { + default: + strtodt(pMinDate, WAREHOUSE_LOAD_DATE); + pMinDate->julian += UPDATE_INTERVAL * (nUpdateNumber - 1); + jtodt(pMinDate, pMinDate->julian); + jtodt(pMaxDate, pMinDate->julian + UPDATE_INTERVAL); + break; + } + + return; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/date.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/date.cpp new file mode 100644 index 0000000000000..182f02a5fe8ac --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/date.cpp @@ -0,0 +1,578 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include +#include "config.h" +#include "porting.h" +#ifndef USE_STDLIB_H +#include +#endif +#include +#include +#include "date.h" +#include "dist.h" +#include "mathops.h" + +#define D_CHARS "ymdYMD24" /* valid characters in a DBGDATE setting */ +#define MIN_DATE_INT 18000101 + +static int m_days[2][13] = { + {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, + {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}}; +static char* qtr_start[5] = {NULL, "01-01", "04-01", "07-01", "10-01"}; +char* weekday_names[8] = { + NULL, + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday"}; +/* + * Routine: mk_date(void) + * Purpose: initialize a date_t + * Algorithm: + * Data Structures: + * Params: + * Returns: date_t * + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +date_t* mk_date(void) { + date_t* res; + + res = (date_t*)malloc(sizeof(struct DATE_T)); + MALLOC_CHECK(res); + + res->flags = 0; + res->year = 0; + res->month = 0; + res->day = 0; + res->julian = 0; + + return (res); +} +/* + * Routine: strtotime(char *str) + * Purpose: convert a string from the time to the number of seconds since + * midnight Algorithm: Data Structures: Params: Returns: int Called By: Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int strtotime(char* str) { + int hour, min, sec, res = 0; + + if (sscanf(str, "%d:%d:%d", &hour, &min, &sec) != 3) { + if (sscanf(str, "%d:%d", &hour, &min) != 2) { + INTERNAL("Invalid time format"); + } + sec = 0; + } + + if (hour > 23 || hour < 0) + INTERNAL("Invalid time format"); + if (min > 59 || min < 0) + INTERNAL("Invalid time format"); + if (sec > 59 || sec < 0) + INTERNAL("Invalid time format"); + + res = hour * 3600 + min * 60 + sec; + + return (res); +} + +/* + * Routine: strtodate(char *str) + * Purpose: initialize a date_t + * Algorithm: + * Data Structures: + * Params: + * Returns: date_t * + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +date_t* strtodate(char* str) { + date_t* res; + + res = (date_t*)malloc(sizeof(struct DATE_T)); + MALLOC_CHECK(res); + + if (sscanf(str, "%d-%d-%d", &res->year, &res->month, &res->day) != 3) + INTERNAL("Badly formed string in call to strtodate()"); + res->flags = 0; + res->julian = dttoj(res); + + return (res); +} + +/* + * Routine: jtodt(int src, date_t *dest) + * Purpose: convert a number of julian days to a date_t + * Algorithm: Fleigel and Van Flandern (CACM, vol 11, #10, Oct. 1968, p. 657) + * Data Structures: + * + * Params: source integer: days since big bang + * Returns: date_t *; NULL on failure + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ +int jtodt(date_t* dest, int src) { + long i = 0, j = 0, l = 0, n = 0; + + if (src < 0) + return (-1); + + dest->julian = src; + l = src + 68569; + n = (int)floor((4 * l) / 146097); + l = l - (int)floor((146097 * n + 3) / 4); + i = (int)floor((4000 * (l + 1) / 1461001)); + l = l - (int)floor((1461 * i) / 4) + 31; + j = (int)floor((80 * l) / 2447); + dest->day = l - (int)floor((2447 * j) / 80); + l = (int)floor(j / 11); + dest->month = j + 2 - 12 * l; + dest->year = 100 * (n - 49) + i + l; + + return (0); +} + +/* + * Routine: dttoj(date_t *) + * Purpose: convert a date_t to a number of julian days + * Algorithm: http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int dttoj(date_t* dt) { + int y, m, res = 0; + + y = dt->year; + m = dt->month; + if (m <= 2) { + m += 12; + y -= 1; + } + + /* + * added 1 to get dttoj and jtodt to match + */ + res = dt->day + (153 * m - 457) / 5 + 365 * y + (int)floor(y / 4) - + (int)floor(y / 100) + (int)floor(y / 400) + 1721118 + 1; + + return (res); +} + +/* + * Routine: strtodt() + * Purpose: Convert an ascii string to a date_t structure + * Algorithm: + * Data Structures: + * + * Params: char *s, date_t *dest + * Returns: int; 0 on success + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: Need to allow for date formats other than Y4MD- + */ +int strtodt(date_t* dest, char* s) { + int nRetCode = 0; + + if (s == NULL) { + dest = NULL; + return (-1); + } + + if (sscanf(s, "%4d-%d-%d", &dest->year, &dest->month, &dest->day) != 3) { + fprintf(stderr, "ERROR: Invalid string to date conversion in strtodt\n"); + nRetCode = -1; + } + + dest->julian = dttoj(dest); + + return (nRetCode); +} + +/* + * Routine: dttostr(date_t *d) + * Purpose: convert a date_t structure to a string + * Algorithm: + * Data Structures: + * + * Params: + * Returns: char *; NULL on failure + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: 20000110 Need to handle more than Y4MD- + */ +char* dttostr(date_t* d) { + static char* res; + static int init = 0; + + if (!init) { + res = (char*)malloc(sizeof(char) * 11); + MALLOC_CHECK(res); + init = 1; + } + + if (d == NULL) + return (NULL); + + sprintf(res, "%4d-%02d-%02d", d->year, d->month, d->day); + + return (res); +} + +/* + * Routine: date_init + * Purpose: set the date handling parameters + * Algorithm: + * Data Structures: + * + * Params: None + * Returns: int; 0 on success + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int date_init(void) { + printf("date_init is not yet complete\n"); + exit(1); + return (0); +} + +/* + * Routine: date_t_op(int op, date_t *operand1, date_t *operand2) + * Purpose: execute arbitrary binary operations on date_t's + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20010806 jms Return code is meaningless + */ +int date_t_op(date_t* dest, int op, date_t* d1, date_t* d2) { + int tJulian; + char tString[11]; + date_t tDate; + + switch (op) { + case OP_FIRST_DOM: /* set to first day of month */ + tJulian = d1->julian - d1->day + 1; + jtodt(dest, tJulian); + break; + case OP_LAST_DOM: /* set to last day of month */ + tJulian = d1->julian - d1->day + m_days[is_leap(d1->year)][d1->month]; + jtodt(dest, tJulian); + break; + case OP_SAME_LY: + if (is_leap(d1->year) && (d1->month == 2) && (d1->day == 29)) + sprintf(tString, "%d-02-28", d1->year - 1); + else + sprintf(tString, "%4d-%02d-%02d", d1->year - 1, d1->month, d1->day); + strtodt(dest, tString); + break; + case OP_SAME_LQ: + switch (d1->month) { + case 1: + case 2: + case 3: + sprintf(tString, "%4d-%s", d1->year, qtr_start[1]); + strtodt(&tDate, tString); + tJulian = d1->julian - tDate.julian; + sprintf(tString, "%4d-%s", d1->year - 1, qtr_start[4]); + strtodt(&tDate, tString); + tJulian += tDate.julian; + jtodt(dest, tJulian); + break; + case 4: + case 5: + case 6: + sprintf(tString, "%4d-%s", d1->year, qtr_start[2]); + strtodt(&tDate, tString); + tJulian = d1->julian - tDate.julian; + sprintf(tString, "%4d-%s", d1->year, qtr_start[1]); + strtodt(&tDate, tString); + tJulian += tDate.julian; + jtodt(dest, tJulian); + break; + case 7: + case 8: + case 9: + sprintf(tString, "%4d-%s", d1->year, qtr_start[3]); + strtodt(&tDate, tString); + tJulian = d1->julian - tDate.julian; + sprintf(tString, "%4d-%s", d1->year, qtr_start[2]); + strtodt(&tDate, tString); + tJulian += tDate.julian; + jtodt(dest, tJulian); + break; + case 10: + case 11: + case 12: + sprintf(tString, "%4d-%s", d1->year, qtr_start[4]); + strtodt(&tDate, tString); + tJulian = d1->julian - tDate.julian; + sprintf(tString, "%4d-%s", d1->year, qtr_start[3]); + strtodt(&tDate, tString); + tJulian += tDate.julian; + jtodt(dest, tJulian); + break; + } + break; + } + + return (0); +} + +/* + * Routine: itodt(date_t *d, int src) + * Purpose: convert a number of days to a date_t + * Algorithm: NOTE: sets only julian field + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int itodt(date_t* dest, int src) { + dest->julian = src; + + return (0); +} + +/* + * Routine: set_dow(date *d) + * Purpose: perpetual calendar stuff + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ +int set_dow(date_t* d) { + int doomsday[4] = {3, 2, 0, 5}; + int known[13] = {0, 3, 0, 0, 4, 9, 6, 11, 8, 5, 10, 7, 12}; + int last_year = -1, dday; + int res = 0, q = 0, r = 0, s = 0; + + if (d->year != last_year) { + if (is_leap(d->year)) { + /* adjust the known dates for january and february */ + known[1] = 4; + known[2] = 1; + } else { + known[1] = 3; + known[2] = 0; + } + + /* calculate the doomsday for the century */ + dday = d->year / 100; + dday -= 15; + dday %= 4; + dday = doomsday[dday]; + + /* and then calculate the doomsday for the year */ + q = d->year % 100; + r = q % 12; + q /= 12; + s = r / 4; + dday += q + r + s; + dday %= 7; + last_year = d->year; + } + + res = d->day; + res -= known[d->month]; + while (res < 0) + res += 7; + while (res > 6) + res -= 7; + + res += dday; + res %= 7; + + return (res); +} + +/* + * Routine: is_leap(year) + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int is_leap(int year) { + return ( + ((year % 100) == 0) ? ((((year % 400) % 2) == 0) ? 1 : 0) + : ((year % 4) == 0) ? 1 + : 0); +} + +/* + * Routine: day_number(date_t *) + * Purpose: + * Algorithm: NOTE: this is NOT the ordinal day in the year, but the ordinal + *reference into the calendar distribution for the day; in particular, this + *needs to skip over the leap day Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int day_number(date_t* d) { + return (m_days[is_leap(d->year)][d->month] + d->day); +} + +/* + * Routine: getDateWeightFromJulian(jDay, nDistribution) + * Purpose: return the weight associated with a particular julian date and + * distribution Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int getDateWeightFromJulian( + int jDay, + int nDistribution, + DSDGenContext& dsdGenContext) { + date_t dTemp; + jtodt(&dTemp, jDay); + int nDay; + nDay = day_number(&dTemp); + + return (dist_weight( + NULL, + "calendar", + nDay, + nDistribution + is_leap(dTemp.year), + dsdGenContext)); +} + +/* + * Routine: date_part(date_t *, int part) + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int date_part(date_t* d, int part) { + switch (part) { + case 1: + return (d->year); + case 2: + return (d->month); + case 3: + return (d->day); + default: + INTERNAL("Invalid call to date_part()"); + return (-1); + } +} + +#ifdef TEST +main() { + date_t* d; + int ret; + + d = mk_date(); + strtodt(d, "1776-07-04"); + ret = set_dow(d); + printf("set_dow(\"1776-07-04\"): wanted 4 got %d\n", ret); + if (ret != 4) { + exit(1); + } + strtodt(d, "2000-01-01"); + ret = set_dow(d); + printf("set_dow(\"2000-01-01\"): wanted 6 got %d\n", ret); + if (ret != 6) { + exit(1); + } + + strtodt(d, "1970-01-01"); + if ((ret = dttoj(d)) != 2440588) { + printf("dttoj returned %d\n", ret); + exit(1); + } + + d->year = 1; + d->month = 11; + d->date = 11; + jtodt(d, 2440588); + if ((d->year != 1970) || (d->month != 1) || (d->date != 1)) { + printf("jtodt failed got: "); + printf("%4d-%02d-%02d", d->year, d->month, d->date); + exit(1); + } + return (0); +} +#endif /* TEST */ \ No newline at end of file diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/dbgen_version.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/dbgen_version.cpp new file mode 100644 index 0000000000000..1b12de84597d4 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/dbgen_version.cpp @@ -0,0 +1,113 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "dbgen_version.h" +#include +#include +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "dist.h" +#include "misc.h" +#include "porting.h" +#include "tables.h" + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int mk_dbgen_version( + void* pDest, + ds_key_t kIndex, + DSDGenContext& dsdGenContext) { + time_t ltime = time_t(); + struct tm* pTimeStamp = nullptr; + struct DBGEN_VERSION_TBL* r; + + if (pDest == NULL) + r = &dsdGenContext.g_dbgen_version; + else + r = static_cast(pDest); + + if (!dsdGenContext.mk_dbgen_version_init) { + memset(&dsdGenContext.g_dbgen_version, 0, sizeof(struct DBGEN_VERSION_TBL)); + dsdGenContext.mk_dbgen_version_init = 1; + } + + time(<ime); /* Get time in seconds */ + pTimeStamp = localtime(<ime); /* Convert time to struct */ + + auto result = sprintf( + r->szDate, + "%4d-%02d-%02d", + pTimeStamp->tm_year + 1900, + pTimeStamp->tm_mon + 1, + pTimeStamp->tm_mday); + if (result < 0) + perror("sprintf failed"); + result = sprintf( + r->szTime, + "%02d:%02d:%02d", + pTimeStamp->tm_hour, + pTimeStamp->tm_min, + pTimeStamp->tm_sec); + if (result < 0) + perror("sprintf failed"); + result = sprintf( + r->szVersion, "%d.%d.%d%s", VERSION, RELEASE, MODIFICATION, PATCH); + if (result < 0) + perror("sprintf failed"); + strcpy(r->szCmdLineArgs, "--this_table_is_rather_pointless"); + + return (0); +} +// +///* +// * Routine: +// * Purpose: +// * Algorithm: +// * Data Structures: +// * +// * Params: +// * Returns: +// * Called By: +// * Calls: +// * Assumptions: +// * Side Effects: +// * TODO: None +// */ +// int pr_dbgen_version(void *pSrc) { +// struct DBGEN_VERSION_TBL *r; +// +// if (pSrc == NULL) +// r = &g_dbgen_version; +// else +// r = pSrc; +// +// print_start(DBGEN_VERSION); +// print_varchar(DV_VERSION, r->szVersion, 1); +// print_varchar(DV_CREATE_DATE, r->szDate, 1); +// print_varchar(DV_CREATE_TIME, r->szTime, 1); +// print_varchar(DV_CMDLINE_ARGS, r->szCmdLineArgs, 0); +// print_end(DBGEN_VERSION); +// +// return (0); +//} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/decimal.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/decimal.cpp new file mode 100644 index 0000000000000..898277ec5adee --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/decimal.cpp @@ -0,0 +1,347 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "config.h" +#include "porting.h" +#ifndef USE_STDLIB_H +#include +#endif +#include +#include "decimal.h" +#include "dist.h" +#include "mathops.h" + +/* + * Routine: set_precision(decimal_t *dest, int size, int precision) + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: None + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void set_precision(decimal_t* dest, int scale, int precision) { + dest->scale = scale; + dest->precision = precision; + dest->number = 0; + dest->flags = 0; + + return; +} + +/* + * Routine: mk_decimal(int size, int precision) + * Purpose: initialize a decimal_t + * Algorithm: + * Data Structures: + * + * Params: int size: total number of places in the decimal + * int precision: number of places in the fraction + * Returns: decimal_t * + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +decimal_t* mk_decimal(int s, int p) { + auto res = (decimal_t*)malloc(sizeof(struct DECIMAL_T)); + + if ((s < 0) || (p < 0)) + return (NULL); + + MALLOC_CHECK(res); + + res->flags = 0; + res->scale = s; + res->precision = p; + res->flags = + static_cast(static_cast(res->flags) | FL_INIT); + + return (res); +} + +/* + * Routine: itodec(int src, decimal_t *dest) + * Purpose: convert an integer to a decimal_t + * Algorithm: + * Data Structures: + * + * Params: source integer + * Returns: decimal_t * + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20000104 need to set errno on error + */ +int itodec(decimal_t* dest, int src) { + int scale = 1, bound = 1; + + while ((bound * 10) <= src) { + scale += 1; + bound *= 10; + } + + dest->precision = 0; + dest->scale = scale; + dest->number = src; + + return (0); +} + +/* + * Routine: ftodec(double f, decimal_t *dec) + * Purpose: Convert a double to a decimal_t + * Algorithm: + * Data Structures: + * + * Params: double f + * Returns: decimal_t * + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int ftodec(decimal_t* dest, double f) { + static char valbuf[20]; + + auto result = snprintf(valbuf, sizeof(valbuf), "%f", f); + if (result < 0) + perror("sprintf failed"); + + return (strtodec(dest, valbuf)); +} + +/* + * Routine: strtodec() + * Purpose: Convert an ascii string to a decimal_t structure + * Algorithm: + * Data Structures: + * + * Params: char *s + * Returns: decimal_t * + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int strtodec(decimal_t* dest, char* s) { + int i; + char* d_pt; + char valbuf[20]; + + if (strlen(s) < 20) { + strcpy(valbuf, s); + } + dest->flags = 0; + if ((d_pt = strchr(valbuf, '.')) == NULL) { + dest->scale = strlen(valbuf); + dest->number = atoi(valbuf); + dest->precision = 0; + } else { + *d_pt = '\0'; + d_pt += 1; + dest->scale = strlen(valbuf); + dest->number = atoi(valbuf); + dest->precision = strlen(d_pt); + for (i = 0; i < dest->precision; i++) + dest->number *= 10; + dest->number += atoi(d_pt); + } + + if (*s == '-' && dest->number > 0) + dest->number *= -1; + + return (0); +} + +/* + * Routine: dectostr(decimal_t *d, char *buf) + * Purpose: convert a decimal structure to a string + * Algorithm: + * Data Structures: + * + * Params: + * Returns: char *; NULL on success + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int dectostr(char* dest, decimal_t* d, DSDGenContext& dsdGenContext) { + ds_key_t number; + int i; + static char szFormat[80]; + + if (!dsdGenContext.dectostr_init) { + auto result = sprintf(szFormat, "%s.%s", HUGE_FORMAT, HUGE_FORMAT); + if (result < 0) + perror("sprintf failed"); + dsdGenContext.dectostr_init = 1; + } + + if (d == NULL || dest == NULL) + return (-1); + for (number = d->number, i = 0; i < d->precision; i++) + number /= 10; + + dest = (char*)malloc(160); + auto result = sprintf(dest, szFormat, number, d->number - number); + if (result < 0) + perror("sprintf failed"); + + return (0); +} + +/* + * Routine: dectof(float *dest, decimal_t *d) + * Purpose: convert a decimal structure to a double + * Algorithm: + * Data Structures: + * + * Params: + * Returns: char *; NULL on success + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int dectoflt(double* dest, decimal_t* d) { + if ((dest == NULL) || (d == NULL)) + return (-1); +#ifdef WIN32 +#pragma warning(disable : 4244) +#endif + *dest = d->number; +#ifdef WIN32 +#pragma warning(default : 4244) +#endif + while (--d->precision > 0) + *dest /= 10.0; + + return (0); +} + +/* + * Routine: decimal_t_op(int op, decimal_t *operand1, decimal_t *operand2) + * Purpose: execute arbitrary binary operations on decimal_t's + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int decimal_t_op(decimal_t* dest, int op, decimal_t* d1, decimal_t* d2) { + int res, np; + float f1, f2; + + if ((d1 == NULL) || (d2 == NULL)) + return (-1); + + dest->scale = (d1->scale > d2->scale) ? d1->scale : d2->scale; + if (d1->precision > d2->precision) { + dest->precision = d1->precision; + } else { + dest->precision = d2->precision; + } + + switch (op) { + case OP_PLUS: + dest->number = d1->number + d2->number; + break; + case OP_MINUS: + dest->number = d1->number - d2->number; + break; + case OP_MULT: + res = d1->precision + d2->precision; + dest->number = d1->number * d2->number; + while (res-- > dest->precision) + dest->number /= 10; + break; + case OP_DIV: + f1 = static_cast(d1->number); + np = d1->precision; + while (np < dest->precision) { + f1 *= 10.0; + np += 1; + } + np = 0; + while (np < dest->precision) { + f1 *= 10.0; + np += 1; + } + f2 = static_cast(d2->number); + np = d2->precision; + while (np < dest->precision) { + f2 *= 10.0; + np += 1; + } + + dest->number = static_cast(f1 / f2); + break; + default: { + auto result = printf("decimal_t_op does not support op %d\n", op); + if (result < 0) + perror("sprintf failed"); + exit(1); + break; + } + } + + return (0); +} + +#ifdef TEST +main() { + decimal_t* res; + int code; + + /* mk_decimal */ + res = mk_decimal(5, 2); + if (res == NULL) { + printf("mk_decimal returned NULL\n"); + exit(-1); + } + + /* itodec */ + itodec(res, 0); + code = dectoi(res); + if (code) { + printf("r_decimal:itodec(0, res) != 0 (%d)\n", code); + exit(-1); + } + + itodec(res, 999); + code = dectoi(res); + if (code != 999) { + printf("r_decimal:itodec(999, res) != 0 (%d)\n", code); + exit(-1); + } + + exit(0); +} +#endif /* TEST */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/dist.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/dist.cpp new file mode 100644 index 0000000000000..778d72497a0b9 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/dist.cpp @@ -0,0 +1,1142 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "config.h" +#include "porting.h" + +#include +#include +#include + +#define MAX_LINE_LEN 120 +#ifdef WIN32 +#define OPTION_START '/' +#else +#define OPTION_START '-' +#endif +#ifdef _WIN32 +#include +#include +#include +#include +#else +#include +#include +#include +#endif +#ifdef NCR +#include +#endif +#ifndef USE_STDLIB_H +#include +#endif +#include "config.h" +#include "date.h" +#include "dcomp.h" +#include "decimal.h" +#include "dist.h" +#include "error_msg.h" +#include "genrand.h" +#include "r_params.h" +#include "tpcds_idx.hpp" +#ifdef TEST +option_t options[] = { + {"DISTRIBUTIONS", + OPT_STR, + 2, + "read distributions from file ", + NULL, + "tester_dist.idx"}, + NULL}; + +char params[2]; +struct { + char* name; +} tdefs[] = {NULL}; +#endif + +/* NOTE: these need to be in sync with a_dist.h */ +#define D_NAME_LEN 20 +#define FL_LOADED 0x01 +static int load_dist(d_idx_t* d); + +#include +#include "config.h" +#include "porting.h" +#include "r_params.h" + +/* + * Routine: release(char *param_name, char *msg) + * Purpose: display version information + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int printReleaseInfo( + const char* param_name, + const char* msg, + DSDGenContext& dsdGenContext) { + auto result = fprintf( + stderr, + "%s Population Generator (Version %d.%d.%d%s)\n", + get_str("PROG", dsdGenContext), + VERSION, + RELEASE, + MODIFICATION, + PATCH); + if (result < 0) + perror("sprintf failed"); + result = fprintf(stderr, "Copyright %s %s\n", COPYRIGHT, C_DATES); + if (result < 0) + perror("sprintf failed"); + + exit(0); +} + +/* + * Routine: usage(char *param_name, char *msg) + * Purpose: display a usage message, with an optional error message + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int usage( + const char* param_name, + const char* msg, + DSDGenContext& dsdGenContext) { + init_params(dsdGenContext); + + auto result = fprintf( + stderr, + "%s Population Generator (Version %d.%d.%d%s)\n", + get_str("PROG", dsdGenContext), + VERSION, + RELEASE, + MODIFICATION, + PATCH); + if (result < 0) + perror("sprintf failed"); + result = fprintf(stderr, "Copyright %s %s\n", COPYRIGHT, C_DATES); + if (result < 0) + perror("sprintf failed"); + + if (msg != NULL) + printf("\nERROR: %s\n\n", msg); + + printf("\n\nUSAGE: %s [options]\n", get_str("PROG", dsdGenContext)); + printf( + "\nNote: When defined in a parameter file (using -p), parmeters " + "should\n"); + printf("use the form below. Each option can also be set from the command\n"); + printf("line, using a form of '%cparam [optional argument]'\n", OPTION_START); + printf("Unique anchored substrings of options are also recognized, and \n"); + printf( + "case is ignored, so '%csc' is equivalent to '%cSCALE'\n\n", + OPTION_START, + OPTION_START); + printf("General Options\n===============\n"); + print_options(dsdGenContext.options, 0, dsdGenContext); + printf("\n"); + printf("Advanced Options\n===============\n"); + print_options(dsdGenContext.options, 1, dsdGenContext); + printf("\n"); + exit((msg == NULL) ? 0 : 1); +} + +/* + * Routine: read_file(char *param_name, char *fname) + * Purpose: process a parameter file + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int read_file( + const char* param_name, + const char* optarg, + DSDGenContext& dsdGenContext) { + FILE* fp = nullptr; + char* cp = nullptr; + char line[MAX_LINE_LEN]; + char name[100]; + int index = 0; + + init_params(dsdGenContext); + + if ((fp = fopen(optarg, "r")) == NULL) + return (-1); + while (fgets(line, MAX_LINE_LEN, fp) != NULL) { + if ((cp = strchr(line, '\n')) != NULL) + *cp = '\0'; + if ((cp = strchr(line, '-')) != NULL) + if (*(cp + 1) == '-') + *cp = '\0'; + if ((cp = strtok(line, " \t=\n")) != NULL) { + strcpy(name, cp); + index = fnd_param(name, dsdGenContext); + if (index == -1) + continue; /* JMS: errors are silently ignored */ + cp += strlen(cp) + 1; + while (*cp && strchr(" \t =", *cp)) + cp++; + + /* command line options over-ride those in a file */ + if (static_cast(dsdGenContext.options[index].flags) & + OPT_SET) + continue; + + if (*cp) { + switch (static_cast(dsdGenContext.options[index].flags) & + TYPE_MASK) { + case OPT_INT: + if ((cp = strtok(cp, " \t\n")) != NULL) + set_option(name, cp); + break; + case OPT_STR: + case OPT_FLG: + set_option(name, cp); + break; + } + } + } + } + + fclose(fp); + + return (0); +} + +/* + * Routine: set_scale() + * Purpose: link SCALE and SCALE_INDEX + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int SetScaleIndex( + const char* szName, + const char* szValue, + DSDGenContext& dsdGenContext) { + char szScale[2]; + int nScale; + + if ((nScale = atoi(szValue)) == 0) + nScale = 1; + + nScale = 1 + static_cast(log10(nScale)); + szScale[0] = '0' + nScale; + szScale[1] = '\0'; + + set_int("_SCALE_INDEX", szScale, dsdGenContext); + + return (atoi(szValue)); +} + +/* + * Routine: print_options(struct OPTION_T *o, int file, int depth) + * Purpose: print a summary of options + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +static void print_options( + struct OPTION_T* o, + int bShowOptional, + DSDGenContext& dsdGenContext) { + int w_adjust = 0, bShow = 0, nCount = 0; + + for (int i = 0; dsdGenContext.options[i].name != NULL; i++) { + /* + * options come in two groups, general and "hidden". Decide which group + * to show in this pass, and ignore others + */ + bShow = 0; + if (bShowOptional && (static_cast(o[i].flags) & OPT_ADV)) + bShow = 1; + if (!bShowOptional && !(static_cast(o[i].flags) & OPT_ADV)) + bShow = 1; + + if (!bShow || (static_cast(o[i].flags) & OPT_HIDE)) + continue; + + nCount += 1; + printf("%s = ", o[i].name); + w_adjust = 15 - strlen(o[i].name); + if (static_cast(o[i].flags) & OPT_INT) + printf(" "); + else if (static_cast(o[i].flags) & OPT_STR) + printf(" "); + else if (static_cast(o[i].flags) & OPT_SUB) + printf(" "); + else if (static_cast(o[i].flags) & OPT_FLG) + printf(" [Y|N] "); + else + printf(" "); + printf("%*s-- %s", w_adjust, " ", o[i].usage); + if (static_cast(o[i].flags) & OPT_NOP) + printf(" NOT IMPLEMENTED"); + printf("\n"); + } + + if (nCount == 0) + printf("None defined.\n"); + + return; +} + +/* + * Routine: di_compare() + * Purpose: comparison routine for two d_idx_t entries; used by qsort + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int di_compare(const void* op1, const void* op2) { + d_idx_t *ie1 = (d_idx_t*)op1, *ie2 = (d_idx_t*)op2; + + return (strcasecmp(ie1->name, ie2->name)); +} + +int load_dists() { + /* open the dist file */ + auto read_ptr = tpcds_idx; + int32_t temp; + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + int entry_count = ntohl(temp); + read_ptr = tpcds_idx + tpcds_idx_len - (entry_count * IDX_SIZE); + for (int i = 0; i < entry_count; i++) { + d_idx_t entry; + memset(&entry, 0, sizeof(const d_idx_t)); + memcpy(entry.name, read_ptr, D_NAME_LEN); + read_ptr += D_NAME_LEN; + entry.name[D_NAME_LEN] = '\0'; + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + entry.index = ntohl(temp); + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + entry.offset = ntohl(temp); + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + entry.str_space = ntohl(temp); + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + entry.length = ntohl(temp); + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + entry.w_width = ntohl(temp); + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + entry.v_width = ntohl(temp); + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + entry.name_space = ntohl(temp); + load_dist(&entry); + auto lockedMap = idx_.wlock(); + lockedMap->emplace(std::string(entry.name), entry); + } + return (1); +} +/* + * Routine: find_dist(char *name, DSDGenContext& dsdGenContext) + * Purpose: translate from dist_t name to d_idx_t * + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +const d_idx_t* find_dist(const char* name) { + std::call_once(initFlag_, []() { load_dists(); }); + + std::string key(name); + auto lockedMap = idx_.rlock(); + if (lockedMap->find(key) != lockedMap->end()) { + return &(lockedMap->at(key)); + } + return nullptr; +} + +/* + * Routine: load_dist(int fd, dist_t *d, DSDGenContext& dsdGenContext) + * Purpose: load a particular distribution + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +static int load_dist(d_idx_t* di) { + int res = 0, i = 0, j = 0; + dist_t* d; + int32_t temp; + FILE* ifp; + + if (di->flags != FL_LOADED) /* make sure no one beat us to it */ + { + auto read_ptr = tpcds_idx; + read_ptr += di->offset; + di->dist = static_cast(malloc(sizeof(struct DIST_T))); + MALLOC_CHECK(di->dist); + d = di->dist; + + /* load the type information */ + d->type_vector = static_cast(malloc(sizeof(int32_t) * di->v_width)); + MALLOC_CHECK(d->type_vector); + for (i = 0; i < di->v_width; i++) { + if (read_ptr) + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + d->type_vector[i] = ntohl(temp); + } + + /* load the weights */ + d->weight_sets = static_cast(malloc(sizeof(int*) * di->w_width)); + d->maximums = static_cast(malloc(sizeof(int32_t) * di->w_width)); + MALLOC_CHECK(d->weight_sets); + MALLOC_CHECK(d->maximums); + for (i = 0; i < di->w_width; i++) { + *(d->weight_sets + i) = + static_cast(malloc(di->length * sizeof(int32_t))); + MALLOC_CHECK(*(d->weight_sets + i)); + d->maximums[i] = 0; + for (j = 0; j < di->length; j++) { + if (read_ptr) + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + *(*(d->weight_sets + i) + j) = ntohl(temp); + /* calculate the maximum weight and convert sets to cummulative + */ + d->maximums[i] += d->weight_sets[i][j]; + d->weight_sets[i][j] = d->maximums[i]; + } + } + + /* load the value offsets */ + d->value_sets = static_cast(malloc(sizeof(int*) * di->v_width)); + MALLOC_CHECK(d->value_sets); + for (i = 0; i < di->v_width; i++) { + *(d->value_sets + i) = + static_cast(malloc(di->length * sizeof(int32_t))); + MALLOC_CHECK(*(d->value_sets + i)); + for (j = 0; j < di->length; j++) { + if (read_ptr) + memcpy(&temp, read_ptr, sizeof(int32_t)); + read_ptr += sizeof(int32_t); + *(*(d->value_sets + i) + j) = ntohl(temp); + } + } + + /* load the column aliases, if they were defined */ + if (di->name_space) { + d->names = static_cast(malloc(di->name_space)); + MALLOC_CHECK(d->names); + if (d->names && read_ptr) + memcpy(d->names, read_ptr, di->name_space * sizeof(char)); + read_ptr += di->name_space * sizeof(char); + } + + /* and finally the values themselves */ + d->strings = static_cast(malloc(sizeof(char) * di->str_space)); + MALLOC_CHECK(d->strings); + if (d->strings && read_ptr) + memcpy(d->strings, read_ptr, di->str_space * sizeof(char)); + read_ptr += di->str_space * sizeof(char); + di->flags = FL_LOADED; + } + + return (res); +} + +/* + * Routine: void *dist_op() + * Purpose: select a value/weight from a distribution + * Algorithm: + * Data Structures: + * + * Params: char *d_name + * int vset: which set of values + * int wset: which set of weights + * Returns: appropriate data type cast as a void * + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: 20000317 Need to be sure this is portable to NT and others + */ +int dist_op( + void* dest, + int op, + const char* d_name, + int vset, + int wset, + int stream, + DSDGenContext& dsdGenContext) { + dist_t* dist = nullptr; + int level = 0, index = 0, dt = 0; + char* char_val = nullptr; + int i_res = 1; + const d_idx_t* d; + + if ((d = find_dist(d_name)) == nullptr) { + char msg[40 + strlen(d_name)]; + auto result = sprintf(msg, "Invalid distribution name '%s'", d_name); + if (result < 0) + perror("sprintf failed"); + INTERNAL(msg); + assert(d != nullptr); + } + + dist = d->dist; + + if (op == 0) { + genrand_integer( + &level, + DIST_UNIFORM, + 1, + dist->maximums[wset - 1], + 0, + stream, + dsdGenContext); + while (level > dist->weight_sets[wset - 1][index] && index < d->length) + index += 1; + dt = vset - 1; + if ((index >= d->length) || (dt > d->v_width)) + INTERNAL("Distribution overrun"); + char_val = dist->strings + dist->value_sets[dt][index]; + } else { + index = vset - 1; + dt = wset - 1; + if (index >= d->length || index < 0) { + auto result = + fprintf(stderr, "Runtime ERROR: Distribution over-run/under-run\n"); + if (result < 0) + perror("sprintf failed"); + result = fprintf( + stderr, + "Check distribution definitions and usage for %s.\n", + d->name); + if (result < 0) + perror("sprintf failed"); + result = fprintf(stderr, "index = %d, length=%d.\n", index, d->length); + if (result < 0) + perror("sprintf failed"); + exit(1); + } + char_val = dist->strings + dist->value_sets[dt][index]; + } + + switch (dist->type_vector[dt]) { + case TKN_VARCHAR: + if (dest) + *static_cast(dest) = static_cast(char_val); + break; + case TKN_INT: + i_res = atoi(char_val); + if (dest) + *static_cast(dest) = i_res; + break; + case TKN_DATE: + if (dest == NULL) { + dest = static_cast(malloc(sizeof(date_t))); + MALLOC_CHECK(dest); + } + strtodt(*static_cast(dest), char_val); + break; + case TKN_DECIMAL: + if (dest == NULL) { + dest = static_cast(malloc(sizeof(decimal_t))); + MALLOC_CHECK(dest); + } + strtodec(*static_cast(dest), char_val); + break; + } + + return ( + (dest == nullptr) + ? i_res + : index + 1); /* shift back to the 1-based indexing scheme */ +} + +/* + * Routine: int dist_weight + * Purpose: return the weight of a particular member of a distribution + * Algorithm: + * Data Structures: + * + * Params: distribution *d + * int index: which "row" + * int wset: which set of weights + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20000405 need to add error checking + */ +int dist_weight( + int* dest, + const char* d, + int index, + int wset, + DSDGenContext& /*dsdGenContext*/) { + dist_t* dist = nullptr; + int res = 0; + const d_idx_t* d_idx; + + if ((d_idx = find_dist(d)) == nullptr) { + char msg[40 + strlen(d)]; + sprintf(msg, "Invalid distribution name '%s'", d); + INTERNAL(msg); + } + + dist = d_idx->dist; + assert(index > 0); + assert(wset > 0); + res = dist->weight_sets[wset - 1][index - 1]; + /* reverse the accumulation of weights */ + if (index > 1) + res -= dist->weight_sets[wset - 1][index - 2]; + + if (dest == nullptr) + return (res); + + *dest = res; + + return (0); +} + +/* + * Routine: int DistNameIndex() + * Purpose: return the index of a column alias + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ +int DistNameIndex( + const char* szDist, + int nNameType, + const char* szName, + DSDGenContext& /*dsdGenContext*/) { + const d_idx_t* d_idx = nullptr; + dist_t* dist = nullptr; + int res = 0; + char* cp = NULL; + + if ((d_idx = find_dist(szDist)) == NULL) + return (-1); + dist = d_idx->dist; + + if (dist->names == NULL) + return (-1); + + res = 0; + cp = dist->names; + do { + if (strcasecmp(szName, cp) == 0) + break; + cp += strlen(cp) + 1; + res += 1; + } while (res < (d_idx->v_width + d_idx->w_width)); + + if (res >= 0) { + if ((nNameType == VALUE_NAME) && (res < d_idx->v_width)) + return (res + 1); + if ((nNameType == WEIGHT_NAME) && (res > d_idx->v_width)) + return (res - d_idx->v_width + 1); + } + + return (-1); +} + +/* + * Routine: int distsize(char *name) + * Purpose: return the size of a distribution + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20000405 need to add error checking + */ +int distsize(const char* name, DSDGenContext& /*dsdGenContext*/) { + const d_idx_t* dist; + + dist = find_dist(name); + + if (dist == NULL) + return (-1); + + return (dist->length); +} + +/* + * Routine: int IntegrateDist(char *szDistName, int nPct, int nStartIndex, int + *nWeightSet) Purpose: return the index of the entry which, starting from + *nStartIndex, would create a range comprising nPct of the total contained in + *nWeightSet NOTE: the value can "wrap" -- that is, the returned value can be + *less than nStartIndex Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ + +int IntegrateDist( + const char* szDistName, + int nPct, + int nStartIndex, + int nWeightSet, + DSDGenContext& dsdGenContext) { + const d_idx_t* pDistIndex = nullptr; + int nGoal = 0, nSize = 0; + + if ((nPct <= 0) || (nPct >= 100)) + return (QERR_RANGE_ERROR); + + pDistIndex = find_dist(szDistName); + if (pDistIndex == NULL) + return (QERR_BAD_NAME); + + if (nStartIndex > pDistIndex->length) + return (QERR_RANGE_ERROR); + + nGoal = pDistIndex->dist->maximums[nWeightSet]; + nGoal = nGoal * nPct / 100; + nSize = distsize(szDistName, dsdGenContext); + + while (nGoal >= 0) { + nStartIndex++; + nGoal -= dist_weight( + nullptr, szDistName, nStartIndex % nSize, nWeightSet, dsdGenContext); + } + + return (nStartIndex); +} + +/* + * Routine: int dist_type(char *name, int nValueSet) + * Purpose: return the type of the n-th value set in a distribution + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ +int dist_type(const char* name, int nValueSet, DSDGenContext& dsdGenContext) { + const d_idx_t* dist; + + dist = find_dist(name); + + if (dist == nullptr) + return (-1); + + if (nValueSet < 1 || nValueSet > dist->v_width) + return (-1); + + return (dist->dist->type_vector[nValueSet - 1]); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void dump_dist(const char* name, DSDGenContext& dsdGenContext) { + const d_idx_t* pIndex = nullptr; + int i, j; + char* pCharVal = nullptr; + int nVal = 0; + + pIndex = find_dist(name); + if (pIndex == nullptr) + ReportErrorNoLine(QERR_BAD_NAME, name, 1); + printf("create %s;\n", pIndex->name); + printf("set types = ("); + for (i = 0; i < pIndex->v_width; i++) { + if (i > 0) + printf(", "); + printf( + "%s", dist_type(name, i + 1, dsdGenContext) == 7 ? "int" : "varchar"); + } + printf(");\n"); + printf("set weights = %d;\n", pIndex->w_width); + for (i = 0; i < pIndex->length; i++) { + printf("add("); + for (j = 0; j < pIndex->v_width; j++) { + if (j) + printf(", "); + if (dist_type(name, j + 1, dsdGenContext) != 7) { + dist_member(&pCharVal, name, i + 1, j + 1, dsdGenContext); + printf("\"%s\"", pCharVal); + } else { + dist_member(&nVal, name, i + 1, j + 1, dsdGenContext); + printf("%d", nVal); + } + } + printf("; "); + for (j = 0; j < pIndex->w_width; j++) { + if (j) + printf(", "); + printf("%d", dist_weight(nullptr, name, i + 1, j + 1, dsdGenContext)); + } + printf(");\n"); + } + + return; +} + +/* + * Routine: dist_active(char *szName, int nWeightSet) + * Purpose: return number of entries with non-zero weght values + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int dist_active( + const char* szName, + int nWeightSet, + DSDGenContext& dsdGenContext) { + int nSize, nResult = 0, i = 0; + + nSize = distsize(szName, dsdGenContext); + for (i = 1; i <= nSize; i++) { + if (dist_weight(nullptr, szName, i, nWeightSet, dsdGenContext) != 0) + nResult += 1; + } + + return (nResult); +} + +/* + * Routine: DistSizeToShiftWidth(char *szDist) + * Purpose: Determine the number of bits required to select a member of the + * distribution Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int DistSizeToShiftWidth( + const char* szDist, + int nWeightSet, + DSDGenContext& dsdGenContext) { + int nBits = 1, nMax; + unsigned int nTotal = 2; + const d_idx_t* d; + + d = find_dist(szDist); + nMax = dist_max(d->dist, nWeightSet, dsdGenContext); + + while (nTotal < nMax) { + nBits += 1; + nTotal <<= 1; + } + + return (nBits); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int MatchDistWeight( + void* dest, + const char* szDist, + int nWeight, + int nWeightSet, + int ValueSet, + DSDGenContext& dsdGenContext) { + const d_idx_t* d = nullptr; + dist_t* dist = nullptr; + int index = 0, dt = 0, i_res = 0, nRetcode = 0; + char* char_val; + + if ((d = find_dist(szDist)) == nullptr) { + char msg[40 + strlen(szDist)]; + sprintf(msg, "Invalid distribution name '%s'", szDist); + INTERNAL(msg); + } + + dist = d->dist; + nWeight %= dist->maximums[nWeightSet - 1]; + + while (nWeight > dist->weight_sets[nWeightSet - 1][index] && + index < d->length) + index += 1; + dt = ValueSet - 1; + if (index >= d->length) + index = d->length - 1; + char_val = dist->strings + dist->value_sets[dt][index]; + + switch (dist->type_vector[dt]) { + case TKN_VARCHAR: + if (dest) + *static_cast(dest) = static_cast(char_val); + break; + case TKN_INT: + i_res = atoi(char_val); + if (dest) + *static_cast(dest) = i_res; + break; + case TKN_DATE: + if (dest == nullptr) { + dest = static_cast(malloc(sizeof(date_t))); + MALLOC_CHECK(dest); + } + strtodt(*static_cast(dest), char_val); + break; + case TKN_DECIMAL: + if (dest == nullptr) { + dest = static_cast(malloc(sizeof(decimal_t))); + MALLOC_CHECK(dest); + } + strtodec(*(decimal_t**)dest, char_val); + break; + } + + nRetcode = 1; + index = 1; + while (index < dist->maximums[nWeightSet - 1]) { + nRetcode += 1; + index *= 2; + } + + return (nRetcode); +} + +/* + * Routine: findDistValue(char *szValue, char *szDistName, int nValueSet) + * Purpose: Return the row number where the entry is found + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20031024 jms this routine needs to handle all data types, not just varchar + */ +int findDistValue( + const char* szValue, + const char* szDistName, + int ValueSet, + DSDGenContext& dsdGenContext) { + char szDistValue[128]; + int nRetValue = 1, nDistMax; + + nDistMax = distsize(szDistName, dsdGenContext); + + for (nRetValue = 1; nRetValue < nDistMax; nRetValue++) { + dist_member(&szDistValue, szDistName, nRetValue, ValueSet, dsdGenContext); + if (strcmp(szValue, szDistValue) == 0) + break; + } + + if (nRetValue <= nDistMax) + return (nRetValue); + return (-1); +} + +void DSDGenContext::Reset() { + init_rand_init = 0; + mk_address_init = 0; + setUpdateDateRange_init = 0; + mk_dbgen_version_init = 0; + getCatalogNumberFromPage_init = 0; + checkSeeds_init = 0; + dateScaling_init = 0; + mk_w_call_center_init = 0; + mk_w_catalog_page_init = 0; + mk_master_catalog_sales_init = 0; + dectostr_init = 0; + date_join_init = 0; + setSCDKeys_init = 0; + scd_join_init = 0; + matchSCDSK_init = 0; + skipDays_init = 0; + mk_w_catalog_returns_init = 0; + mk_detail_catalog_sales_init = 0; + mk_w_customer_init = 0; + mk_w_date_init = 0; + mk_w_inventory_init = 0; + mk_w_item_init = 0; + mk_w_promotion_init = 0; + mk_w_reason_init = 0; + mk_w_ship_mode_init = 0; + mk_w_store_returns_init = 0; + mk_master_store_sales_init = 0; + mk_w_store_init = 0; + mk_w_web_page_init = 0; + mk_w_web_returns_init = 0; + mk_master_init = 0; + mk_detail_init = 0; + mk_w_web_site_init = 0; + mk_cust_init = 0; + mk_order_init = 0; + mk_part_init = 0; + mk_supp_init = 0; + dbg_text_init = 0; + find_dist_init = 0; + cp_join_init = 0; + web_join_init = 0; + set_pricing_init = 0; + init_params_init = 0; + get_rowcount_init = 0; + mk_detail_web_sales_init = 0; + mk_master_web_sales_init = 0; +} + +#ifdef TEST +main() { + int i_res; + char* c_res; + decimal_t dec_res; + + init_params(); + + dist_member(&i_res, "test_dist", 1, 1); + if (i_res != 10) { + printf("dist_member(\"test_dist\", 1, 1): %d != 10\n", i_res); + exit(1); + } + dist_member(&i_res, "test_dist", 1, 2); + if (i_res != 60) { + printf("dist_member(\"test_dist\", 1, 2): %d != 60\n", i_res); + exit(1); + } + dist_member((void*)&c_res, "test_dist", 1, 3); + if (strcmp(c_res, "El Camino")) { + printf("dist_member(\"test_dist\", 1, 3): %s != El Camino\n", c_res); + exit(1); + } + dist_member((void*)&dec_res, "test_dist", 1, 4); + if (strcmp(dec_res.number, "1") || strcmp(dec_res.fraction, "23")) { + printf( + "dist_member(\"test_dist\", 1, 4): %s.%s != 1.23\n", + dec_res.number, + dec_res.fraction); + exit(1); + } + dist_weight(&i_res, "test_dist", 2, 2); + if (3 != i_res) { + printf("dist_weight(\"test_dist\", 2, 2): %d != 3\n", i_res); + exit(1); + } +} +#endif /* TEST */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/error_msg.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/error_msg.cpp new file mode 100644 index 0000000000000..eb1792eba1c70 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/error_msg.cpp @@ -0,0 +1,237 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "error_msg.h" +#include +#include +#include +#include "config.h" +#include "grammar_support.h" +#include "porting.h" +static int* LN; +static char* FN; + +err_msg_t Errors[MAX_ERROR + 2] = { + { + EFLG_NO_ARG, + "", + }, + {EFLG_STR_ARG, "File '%s' not found"}, + {EFLG_NO_ARG, "Line exceeds maximum leng.h"}, + {EFLG_STR_ARG, "Memory allocation failed %s"}, + {EFLG_STR_ARG, "Syntax Error: \n'%s'"}, + {EFLG_NO_ARG, "Invalid/Out-of-range Argument"}, + {EFLG_STR_ARG, "'%s' is not a unique name"}, + {EFLG_STR_ARG, "'%s' is not a valid name"}, + {EFLG_NO_ARG, "Command parse failed"}, + {EFLG_NO_ARG, "Invalid tag found"}, + {EFLG_STR_ARG, "Read failed on '%s'"}, + {EFLG_NO_ARG, "Too Many Templates!"}, + {EFLG_NO_ARG, "Each workload definition must be in its own file"}, + {EFLG_NO_ARG, + "Query Class name must be unique within a workload definition"}, + {EFLG_NO_ARG, "Query Template must be unique within a query class"}, + {EFLG_STR_ARG | EFLG_SYSTEM, "Open failed on '%s'"}, + {EFLG_STR_ARG, "%s not yet implemented"}, /* QERR_NOT_IMPLEMENTED */ + {EFLG_STR_ARG, "string trucated to '%s'"}, + {EFLG_NO_ARG, "Non-terminated string"}, + {EFLG_STR_ARG, "failed to write to '%s'"}, + {EFLG_NO_ARG, "No type vector defined for distribution"}, + {EFLG_NO_ARG, "No weight count defined for distribution"}, + {EFLG_NO_ARG, "No limits defined for pricing calculations"}, + {EFLG_STR_ARG, "Percentage is out of bounds in substitution '%s'"}, + {EFLG_STR_ARG, "Name is not a distribution or table name: '%s'"}, + {EFLG_NO_ARG, "Cannot evaluate expression"}, + {EFLG_STR_ARG, + "Substitution'%s' is used before being initialized"}, /* QERR_NO_INIT + */ + {EFLG_NO_ARG, + "RANGE()/LIST()/ULIST() not supported for NORMAL " + "distributions"}, + {EFLG_STR_ARG, "Bad Nesting; '%s' not found"}, + {EFLG_STR_ARG, "Include stack overflow when opening '%s'"}, + {EFLG_STR_ARG, "Bad function call: '%s'"}, + {EFLG_STR_ARG, "Bad Hierarchy Call: '%s'"}, + {EFLG_NO_ARG, "Must set types and weights before defining names"}, + {EFLG_NO_ARG, "More than 20 arguments in definition"}, + {EFLG_NO_ARG, "Argument type mismat.h"}, + {EFLG_NO_ARG, + "RANGE()/LIST()/ULIST() cannot be used in the " + "same expression"}, /* QERR_RANGE_LIST + */ + {EFLG_NO_ARG, "Selected scale factor is NOT valid for result publication"}, + {EFLG_STR_ARG, "Parameter setting failed for '%s'"}, + {EFLG_STR_ARG, "Table %s is being joined without an explicit rule"}, + {EFLG_STR_ARG, "Table %s is not yet fully defined"}, + {EFLG_STR_ARG, + "Table %s is a child; it is populated during the build of " + "its parent (e.g., catalog_sales builds catalog returns)"}, + {EFLG_NO_ARG, + "Command line arguments for dbgen_version exceed 200 " + "characters; truncated"}, + {EFLG_NO_ARG, + "A query template list must be supplied using the " + "INPUT option"}, /* QERR_NO_QUERYLIST + */ + {EFLG_NO_ARG, + "Invalid query number found in permutation!"}, /* QERR_QUERY_RANGE + */ + {EFLG_NO_ARG, + "RANGE/LIST/ULIST expressions not valid as " + "function parameters"}, /* QERR_MODIFIED_PARAM + */ + {EFLG_NO_ARG, + "RANGE/LIST/ULIST truncated to available " + "values"}, /* QERR_MODIFIED_PARAM + */ + {EFLG_NO_ARG, + "This scale factor is valid for QUALIFICATION " + "ONLY"}, /* QERR_QUALIFICATION_SCALE + */ + {EFLG_STR_ARG, + "Generating %s requires the '-update' option"}, /* QERR_TABLE_UPDATE + */ + {0, NULL}}; + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void ProcessErrorCode( + int nErrorCode, + char* szRoutineName, + char* szParam, + int nParam) { + switch (nErrorCode) { + case QERR_NO_FILE: + ReportError(QERR_NO_FILE, szParam, 1); + break; + case QERR_SYNTAX: + case QERR_RANGE_ERROR: + case QERR_NON_UNIQUE: + case QERR_BAD_NAME: + case QERR_DEFINE_OVERFLOW: + case QERR_INVALID_TAG: + case QERR_READ_FAILED: + case QERR_NO_MEMORY: + case QERR_LINE_TOO_LONG: + ReportError(nErrorCode, szRoutineName, 1); + break; + } + return; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int ReportError(int nError, const char* msg, int bExit) { + auto result = fprintf(stderr, "ERROR?!\n"); + if (result < 0) + perror("sprintf failed"); + return (nError); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int ReportErrorNoLine(int nError, const char* msg, int bExit) { + if (nError < MAX_ERROR) { + switch (static_cast(Errors[-nError].flags) & EFLG_ARG_MASK) { + case EFLG_NO_ARG: { + auto result = fprintf( + stderr, + "%s: %s\n", + (bExit) ? "ERROR" : "Warning", + Errors[-nError].prompt); + if (result < 0) + perror("sprintf failed"); + break; + } + case EFLG_STR_ARG: { + auto prompt = Errors[std::min( + static_cast(-nError), + static_cast(MAX_ERROR + 1))] + .prompt; + char e_msg[1024 + strlen(prompt) + strlen(msg)]; + auto result = sprintf(e_msg, prompt, msg); + if (result < 0) + perror("sprintf failed"); + result = + fprintf(stderr, "%s: %s\n", (bExit) ? "ERROR" : "Warning", e_msg); + if (result < 0) + perror("sprintf failed"); + break; + } + } + + if (static_cast(Errors[static_cast(-nError)].flags) & + EFLG_SYSTEM) + perror(msg); + } + + if (bExit) + exit(nError); + else + return (nError); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void SetErrorGlobals(char* szFileName, int* nLineNumber) { + FN = szFileName; + LN = nLineNumber; + + return; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/genrand.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/genrand.cpp new file mode 100644 index 0000000000000..585ad51e89c92 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/genrand.cpp @@ -0,0 +1,703 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include +#include +#include "config.h" +#include "porting.h" +#ifdef WIN32 +#include +#include +#endif +#include "config.h" +#include "date.h" +#include "decimal.h" +#include "dist.h" +#include "genrand.h" +#include "params.h" +#include "porting.h" +#include "r_params.h" + +#include "columns.h" +#include "streams.h" +#include "tables.h" + +static long Mult = 16807; /* the multiplier */ +static long nQ = 127773; /* the quotient MAXINT / Mult */ +static long nR = 2836; /* the remainder MAXINT % Mult */ +void DSNthElement(HUGE_TYPE N, int nStream, DSDGenContext& dsdGenContext); + +/* + * Routine: next_random(int stream, DSDGenContext& dsdGenContext) + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +long next_random(int stream, DSDGenContext& dsdGenContext) { + long s = dsdGenContext.Streams[stream].nSeed, div_res, mod_res; + + div_res = s / nQ; + mod_res = s - nQ * div_res; /* i.e., mod_res = s % nQ */ + s = Mult * mod_res - div_res * nR; + if (s < 0) + s += MAXINT; + dsdGenContext.Streams[stream].nSeed = s; + dsdGenContext.Streams[stream].nUsed += 1; +#ifdef JMS + dsdGenContext.Streams[stream].nTotal += 1; +#endif + return (s); +} + +/* + * Routine: next_random_float(int stream) + * Purpose: return random in [0..1] + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +double next_random_float(int stream, DSDGenContext& dsdGenContext) { + long res; + + res = next_random(stream, dsdGenContext); + + return (static_cast(res) / static_cast(MAXINT)); +} + +/* + * Routine: skip_random(int stream, int skip_count, DSDGenContext& + * dsdGenContext) Purpose: Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void skip_random(int nStream, ds_key_t N, DSDGenContext& dsdGenContext) { + ds_key_t Z; + ds_key_t M; + +#ifdef UNDEF + fprintf(stderr, "skipping stream %d to %d\n", nStream, N); + Streams[nStream].nTotal = N; +#endif + M = Mult; + Z = static_cast(dsdGenContext.Streams[nStream].nInitialSeed); + while (N > 0) { + if (N % 2 != 0) /* testing for oddness, this seems portable */ + Z = (M * Z) % MAXINT; + N = N / 2; /* integer division, truncates */ + M = (M * M) % MAXINT; + } + dsdGenContext.Streams[nStream].nSeed = static_cast(Z); + + return; +} + +/* + * Routine: genrand_integer(int dist, int min, int max, int mean, dsdGenContext) + * Purpose: generate a random integer given the distribution and limits + * Algorithm: + * Data Structures: + * + * Params: + * Returns: int + * Called By: + * Calls: + * Assumptions: + * Side Effects: + */ +int genrand_integer( + int* dest, + int dist, + int min, + int max, + int mean, + int stream, + DSDGenContext& dsdGenContext) { + int res = 0, i; + double fres = 0; + + switch (dist) { + case DIST_UNIFORM: + res = next_random(stream, dsdGenContext); + res %= max - min + 1; + res += min; + break; + case DIST_EXPONENTIAL: + for (i = 0; i < 12; i++) + fres += + static_cast(next_random(stream, dsdGenContext) / MAXINT) - + 0.5; + res = min + static_cast((max - min + 1) * fres); + break; + default: + INTERNAL("Undefined distribution"); + break; + } + + if (dest == nullptr) + return (res); + + *dest = res; + + return (0); +} + +/* + * Routine: genrand_key(ket_t *dest, int dist, ds_key_t min, ds_key_t max, + * ds_key_t mean, int stream, DSDGenContext& dsdGenContext) Purpose: generate a + * random integer given the distribution and limits Algorithm: Data Structures: + * + * Params: + * Returns: ds_key_t + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: Need to rework to rely on RNG routines that will work for 64 bit return + * values + */ +ds_key_t genrand_key( + ds_key_t* dest, + int dist, + ds_key_t min, + ds_key_t max, + ds_key_t mean, + int stream, + DSDGenContext& dsdGenContext) { + int res = 0, i; + double fres = 0; + + switch (dist) { + case DIST_UNIFORM: + res = next_random(stream, dsdGenContext); + res %= static_cast(max - min + 1); + res += static_cast(min); + break; + case DIST_EXPONENTIAL: + for (i = 0; i < 12; i++) + fres += + static_cast(next_random(stream, dsdGenContext) / MAXINT) - + 0.5; + res = static_cast(min) + static_cast((max - min + 1) * fres); + break; + default: + INTERNAL("Undefined distribution"); + break; + } + + if (dest == nullptr) + return (static_cast(res)); + + *dest = static_cast(res); + + return (static_cast(0)); +} + +/* + * Routine: + * genrand_decimal(int dist, decimal_t *min, decimal_t *max, decimal_t + **mean), dsdGenContext Purpose: create a random decimal_t Algorithm: Data + *Structures: + * + * Params: min/max are char * to allow easy passing of precision + * Returns: decimal_t *; NULL on failure + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int genrand_decimal( + decimal_t* dest, + int dist, + decimal_t* min, + decimal_t* max, + decimal_t* mean, + int stream, + DSDGenContext& dsdGenContext) { + int i; + decimal_t res; + double fres = 0.0; + + if (min->precision < max->precision) + dest->precision = min->precision; + else + dest->precision = max->precision; + + switch (dist) { + case DIST_UNIFORM: + res.number = next_random(stream, dsdGenContext); + res.number %= max->number - min->number + 1; + res.number += min->number; + break; + case DIST_EXPONENTIAL: + for (i = 0; i < 12; i++) { + fres /= 2.0; + fres += static_cast( + static_cast(next_random(stream, dsdGenContext)) / + static_cast(MAXINT)) - + 0.5; + } + res.number = mean->number + + static_cast((max->number - min->number + 1) * fres); + break; + default: + INTERNAL("Undefined distribution"); + break; + } + + dest->number = res.number; + i = 0; + while (res.number > 10) { + res.number /= 10; + i += 1; + } + dest->scale = i; + + return (0); +} + +/* Routine: RNGReset(int tbl) + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int RNGReset(int tbl, DSDGenContext& dsdGenContext) { + int i; + + for (i = 0; dsdGenContext.Streams[i].nColumn != -1; i++) + if (dsdGenContext.Streams[i].nTable == tbl) + dsdGenContext.Streams[i].nSeed = dsdGenContext.Streams[i].nInitialSeed; + + return (0); +} + +/* WARNING! This routine assumes the existence of 64-bit */ + +/* integers. The notation used here- "HUGE" is *not* ANSI standard. */ + +/* Hopefully, you have this extension as well. If not, use whatever */ + +/* nonstandard trick you need to in order to get 64 bit integers. */ + +/* The book says that this will work if MAXINT for the type you choose */ + +/* is at least 2**46 - 1, so 64 bits is more than you *really* need */ + +static HUGE_TYPE Multiplier = 16807; /* or whatever nonstandard */ +static HUGE_TYPE Modulus = 2147483647; /* trick you use to get 64 bit int */ + +/* Advances value of Seed after N applications of the random number generator + with multiplier Mult and given Modulus. + NthElement(Seed[],count); + + Theory: We are using a generator of the form + X_n = [Mult * X_(n-1)] mod Modulus. It turns out that + X_n = [(Mult ** n) X_0] mod Modulus. + This can be computed using a divide-and-conquer technique, see + the code below. + + In words, this means that if you want the value of the Seed after n + applications of the generator, you multiply the initial value of the + Seed by the "super multiplier" which is the basic multiplier raised + to the nth power, and then take mod Modulus. +*/ + +/* Nth Element of sequence starting with StartSeed */ +void DSNthElementNthElement( + HUGE_TYPE N, + int nStream, + DSDGenContext& dsdGenContext) { + HUGE_TYPE Z; + HUGE_TYPE Mult; + + Mult = Multiplier; + Z = static_cast(dsdGenContext.Streams[nStream].nInitialSeed); + while (N > 0) { + if (N % 2 != 0) /* testing for oddness, this seems portable */ + { +#ifdef JMS + dsdGenContext.Streams[nStream].nTotal += 1; +#endif + Z = (Mult * Z) % Modulus; + } + N = N / 2; /* integer division, truncates */ + Mult = (Mult * Mult) % Modulus; +#ifdef JMS + dsdGenContext.Streams[nStream].nTotal += 2; +#endif + } + dsdGenContext.Streams[nStream].nSeed = static_cast(Z); + + return; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int dump_seeds_ds(int tbl, DSDGenContext& dsdGenContext) { + int i; + + for (i = 0; dsdGenContext.Streams[i].nColumn != -1; i++) + if (dsdGenContext.Streams[i].nTable == tbl) { + auto result = printf( + "%04d\t%09d\t%09ld\n", + i, + dsdGenContext.Streams[i].nUsed, + dsdGenContext.Streams[i].nSeed); + if (result < 0) + perror("sprintf failed"); + } + return (0); +} + +/* + * Routine: gen_charset(char *set, int min, int max) + * Purpose: generate random characters from set for a random length [min..max] + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int gen_charset( + char* dest, + char* set, + int min, + int max, + int stream, + DSDGenContext& dsdGenContext) { + int len, i, temp; + + if (set == NULL) { + dest = NULL; + return (-1); + } + + genrand_integer(&len, DIST_UNIFORM, min, max, 0, stream, dsdGenContext); + + for (i = 0; i < max; i++) { + genrand_integer( + &temp, DIST_UNIFORM, 0, strlen(set) - 1, 0, stream, dsdGenContext); + if (i < len) + dest[i] = *(set + temp); + } + dest[len] = '\0'; + + return (0); +} + +/* + * Routine: genrand_date(int dist, date_t *min, date_t *max, DSDGenContext& + * dsdGenContext) Purpose: generate random date within [min..max] Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int genrand_date( + date_t* dest, + int dist, + date_t* min, + date_t* max, + date_t* mean, + int stream, + DSDGenContext& dsdGenContext) { + int range, imean = 0, temp, idt, nYear, nTotalWeight = 0, nDayCount; + + idt = dttoj(min); + range = dttoj(max); + range -= idt; + nDayCount = min->day; + nYear = min->year; + + switch (dist) { + case DIST_SALES: + case DIST_RETURNS: + /* walk from min to max to "integrate" the distribution */ + while (range -= 1) { + nTotalWeight += dist_weight( + NULL, "calendar", nDayCount, dist + is_leap(nYear), dsdGenContext); + if (nDayCount == 365 + is_leap(nYear)) { + nYear += 1; + nDayCount = 1; + } else + nDayCount += 1; + } + /* pick a value in the resulting range */ + temp = genrand_integer( + NULL, DIST_UNIFORM, 1, nTotalWeight, 0, stream, dsdGenContext); + /* and walk it again to translate that back to a date */ + nDayCount = min->day; + idt = min->julian; + nYear = min->year; + while (temp >= 0) { + temp -= dist_weight( + NULL, "calendar", nDayCount, dist + is_leap(nYear), dsdGenContext); + nDayCount += 1; + idt += 1; + if (nDayCount > 365 + is_leap(nYear)) { + nYear += 1; + nDayCount = 1; + } + } + break; + case DIST_EXPONENTIAL: + imean = dttoj(mean); + imean -= idt; + case DIST_UNIFORM: + genrand_integer(&temp, dist, 0, range, imean, stream, dsdGenContext); + idt += temp; + break; + default: + break; + } + + jtodt(dest, idt); + + return (0); +} + +/************** + ************** + ** + ** static routines + ** + ************** + **************/ + +/* + * Routine: init_rand(DSDGenContext& dsdGenContext) + * Purpose: Initialize the RNG used throughout the code + * Algorithm: To allow two columns to use the same stream of numbers (for + *joins), pre-sort the streams list by Duplicate and then assign values. Order + *by column after initialization Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ +// FIXME: allow re-init +void init_rand(DSDGenContext& dsdGenContext) { + long long i, skip, nSeed; // changed to long long from int + + if (!dsdGenContext.init_rand_init) { + if (is_set("RNGSEED", dsdGenContext)) + nSeed = get_int("RNGSEED", dsdGenContext); + else + nSeed = RNG_SEED; + skip = MAXINT / MAX_COLUMN; + for (i = 0; i < MAX_COLUMN; i++) { + // simulate the overflow as if it were an int + if (i != 0 && (INT_MAX - nSeed) / i < skip) { + long long val = nSeed + skip * i; + val %= MAXINT; + val -= MAXINT; + val -= 2; + dsdGenContext.Streams[i].nInitialSeed = val; + dsdGenContext.Streams[i].nSeed = val; + } else { + dsdGenContext.Streams[i].nInitialSeed = nSeed + skip * i; + dsdGenContext.Streams[i].nSeed = nSeed + skip * i; + } + dsdGenContext.Streams[i].nUsed = 0; + } + dsdGenContext.init_rand_init = 1; + } + return; +} + +void resetSeeds(int nTable, DSDGenContext& dsdGenContext) { + int i; + + for (i = 0; i < MAX_COLUMN; i++) + if (dsdGenContext.Streams[i].nTable == nTable) + dsdGenContext.Streams[i].nSeed = dsdGenContext.Streams[i].nInitialSeed; + return; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void genrand_email( + char* pEmail, + char* pFirst, + char* pLast, + int nColumn, + DSDGenContext& dsdGenContext) { + char* pDomain = nullptr; + char szCompany[50]; + int nCompanyLength; + + pick_distribution(&pDomain, "top_domains", 1, 1, nColumn, dsdGenContext); + genrand_integer( + &nCompanyLength, DIST_UNIFORM, 10, 20, 0, nColumn, dsdGenContext); + gen_charset(&szCompany[0], ALPHANUM, 1, 20, nColumn, dsdGenContext); + szCompany[nCompanyLength] = '\0'; + + if ((strlen(pFirst) + strlen(pLast) + strlen(szCompany) + strlen(pDomain) + + 3) < (RS_C_EMAIL + 1)) { + auto result = + sprintf(pEmail, "%s.%s@%s.%s", pFirst, pLast, szCompany, pDomain); + if (result < 0) + perror("sprintf failed"); + } + + return; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void genrand_ipaddr(char* pDest, int nColumn, DSDGenContext& dsdGenContext) { + int arQuads[4], i; + + for (i = 0; i < 4; i++) + genrand_integer( + &arQuads[i], DIST_UNIFORM, 1, 255, 0, nColumn, dsdGenContext); + auto result = sprintf( + pDest, + "%03d.%03d.%03d.%03d", + arQuads[0], + arQuads[1], + arQuads[2], + arQuads[3]); + if (result < 0) + perror("sprintf failed"); + + return; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int genrand_url(char* pDest, int nColumn) { + strcpy(pDest, "http://www.foo.com"); + + return (0); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int setSeed(int nStream, int nValue, DSDGenContext& dsdGenContext) { + int nRetValue; + + nRetValue = dsdGenContext.Streams[nStream].nSeed; + dsdGenContext.Streams[nStream].nSeed = nValue; + + return (nRetValue); +} + +#ifdef TEST +main() { + printf("r_genrand:No test routine has been defined for this module\n"); + + exit(0); +} +#endif /* TEST */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/join.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/join.cpp new file mode 100644 index 0000000000000..1a3b1fcf00f39 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/join.cpp @@ -0,0 +1,455 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "constants.h" +#include "date.h" +#include "decimal.h" +#include "dist.h" +#include "error_msg.h" +#include "genrand.h" +#include "porting.h" +#include "r_params.h" +#include "scaling.h" +#include "scd.h" +#include "sparse.h" +#include "tables.h" +#include "tdefs.h" +#include "tpcds.idx.h" +#include "w_web_sales.h" + +ds_key_t web_join(int col, ds_key_t join_key, DSDGenContext& dsdGenContext); + +/* + * Routine: date_join(int from_tbl, int join_count) + * Purpose: account for the different date-adjusted patterns in the data set + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: Relies on existing RNG code, which isn't really 64bit; will probably + * requre a rework of the genrand_xx routines + */ +static ds_key_t date_join( + int from_tbl, + int from_col, + ds_key_t join_count, + int nYear, + DSDGenContext& dsdGenContext) { + int nDay, nTemp, nMin = -1, nMax = -1, nResult; + int jToday; + date_t TempDate; + + strtodt(&TempDate, TODAYS_DATE); + jToday = dttoj(&TempDate); + + switch (from_tbl) { + case STORE_SALES: + case CATALOG_SALES: + case WEB_SALES: + pick_distribution( + &nDay, + "calendar", + 1, + calendar_sales + is_leap(nYear), + from_col, + dsdGenContext); + break; + + /* + * returns are keyed to the sale date, with the lag between sale and return + * selected within a known range, based on sales channel + */ + case STORE_RETURNS: + nMin = SS_MIN_SHIP_DELAY; + nMax = SS_MAX_SHIP_DELAY; + case CATALOG_RETURNS: + if (nMin == -1) { + nMin = CS_MIN_SHIP_DELAY; + nMax = CS_MAX_SHIP_DELAY; + } + case WEB_RETURNS: + if (nMin == -1) { + nMin = WS_MIN_SHIP_DELAY; + nMax = WS_MAX_SHIP_DELAY; + } + genrand_integer( + &nTemp, DIST_UNIFORM, nMin * 2, nMax * 2, 0, from_col, dsdGenContext); + return (join_count + nTemp); + break; + case WEB_SITE: + case WEB_PAGE: + return (web_join(from_col, join_count, dsdGenContext)); + default: + pick_distribution( + &nDay, "calendar", 1, 1 + is_leap(nYear), from_col, dsdGenContext); + break; + } + + TempDate.year = nYear; + TempDate.month = 1; + TempDate.day = 1; + + nResult = dttoj(&TempDate) + nDay; + + return (static_cast(nResult > jToday) ? -1 : nResult); +} + +/* + * Routine: time_join(int from_tbl, int join_count) + * Purpose: create joins that are time-skewed + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: Relies on existing RNG code, which isn't really 64bit; will probably + * requre a rework of the genrand_xx routines + */ +ds_key_t time_join( + int to_tbl, + int to_col, + ds_key_t join_count, + DSDGenContext& dsdGenContext) { + int hour, secs; + + switch (to_tbl) { + case STORE_SALES: + case STORE_RETURNS: + pick_distribution(&hour, "hours", 1, 2, to_col, dsdGenContext); + break; + case CATALOG_SALES: + case WEB_SALES: + case CATALOG_RETURNS: + case WEB_RETURNS: + pick_distribution(&hour, "hours", 1, 3, to_col, dsdGenContext); + break; + default: + pick_distribution(&hour, "hours", 1, 1, to_col, dsdGenContext); + break; + } + genrand_integer(&secs, DIST_UNIFORM, 0, 3599, 0, to_col, dsdGenContext); + + return (static_cast(hour * 3600 + secs)); +} + +/* + * Routine: cp_join(int from_tbl, int join_count) + * Purpose: create joins to catalog_page + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +static ds_key_t +cp_join(int tbl, int col, ds_key_t jDate, DSDGenContext& dsdGenContext) { + ds_key_t res; + static int nPagePerCatalog; + int nType, nCount, nOffset, nPage; + static date_t dTemp; + char* szTemp = nullptr; + + if (!dsdGenContext.cp_join_init) { + nPagePerCatalog = + (static_cast(get_rowcount(CATALOG_PAGE, dsdGenContext)) / + CP_CATALOGS_PER_YEAR) / + (YEAR_MAXIMUM - YEAR_MINIMUM + 2); + strtodt(&dTemp, DATA_START_DATE); + dsdGenContext.cp_join_init = 1; + } + + nType = + pick_distribution(&szTemp, "catalog_page_type", 1, 2, col, dsdGenContext); + genrand_integer( + &nPage, DIST_UNIFORM, 1, nPagePerCatalog, 0, col, dsdGenContext); + nOffset = static_cast(jDate) - dTemp.julian - 1; + nCount = (nOffset / 365) * CP_CATALOGS_PER_YEAR; + nOffset %= 365; + + switch (nType) { + case 1: /* bi-annual */ + if (nOffset > 183) + nCount += 1; + break; + case 2: /* quarterly */ + nCount += (nOffset / 91); + break; + case 3: /* monthly */ + nCount += (nOffset / 31); + break; + } + + res = CP_SK(nCount, nPagePerCatalog, nPage); + + return (res); +} +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t getCatalogNumberFromPage( + ds_key_t kPageNumber, + DSDGenContext& dsdGenContext) { + static int nPagePerCatalog; + + if (!dsdGenContext.getCatalogNumberFromPage_init) { + nPagePerCatalog = + (static_cast(get_rowcount(CATALOG_PAGE, dsdGenContext)) / + CP_CATALOGS_PER_YEAR) / + (YEAR_MAXIMUM - YEAR_MINIMUM + 2); + dsdGenContext.getCatalogNumberFromPage_init = 1; + } + + return (kPageNumber / nPagePerCatalog); +} + +/* + * Routine: web_join(int col, ds_key_t join_key, DSDGenContext& dsdGenContext) + * Purpose: create joins to web_site/web_page. These need to be handled + *together, since the date of transaction must fit within the lifetime of a + *particular page, which must fit within the lifetime of a particular site Data + *Structures: + * + * Params: + * join_key is one of two things: + * 1. the xxx_sk for a particular row in the dimension for which we + *need appropriate dates + * 2. a julian date for which we need to pick a valid xxx_sk value + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t web_join(int col, ds_key_t join_key, DSDGenContext& dsdGenContext) { + ds_key_t res = -1, kSite; + static int nConcurrentSites, nSiteDuration, nOffset; + static date_t dSiteOpen, /* open/close dates for current web site */ + dSiteClose; + int nTemp; + tdef* pWS = getSimpleTdefsByNumber(WEB_SITE, dsdGenContext); + tdef* pWP = getSimpleTdefsByNumber(WEB_PAGE, dsdGenContext); + + if (!dsdGenContext.web_join_init) { + strtodt(&dSiteClose, WEB_END_DATE); + nSiteDuration = dSiteClose.julian; + nConcurrentSites = + static_cast(get_rowcount(CONCURRENT_WEB_SITES, dsdGenContext)); + strtodt(&dSiteOpen, WEB_START_DATE); + nSiteDuration -= dSiteOpen.julian; + nSiteDuration *= nConcurrentSites; + nOffset = (dSiteClose.julian - dSiteOpen.julian) / (2 * nSiteDuration); + dsdGenContext.web_join_init = 1; + } + + switch (col) { + /************** + * join_key is the xxx_sk value for a dimension + */ + case WEB_OPEN_DATE: + strtodt(&dSiteOpen, DATE_MINIMUM); + res = dSiteOpen.julian - + ((join_key * WEB_DATE_STAGGER) % nSiteDuration / 2); + if (WEB_IS_REPLACED(join_key)) /* this site is completely replaced */ + { + if (WEB_IS_REPLACEMENT(join_key)) /* this is the second site */ + { + /* the open date of the second site needs to align on a revision + * boundary */ + res += nOffset * nSiteDuration; + } + } + break; + case WEB_CLOSE_DATE: + strtodt(&dSiteOpen, DATE_MINIMUM); + res = dSiteOpen.julian - + ((join_key * WEB_DATE_STAGGER) % nSiteDuration / 2); + res += pWS->nParam * nSiteDuration; + if (WEB_IS_REPLACED(join_key)) /* this site is completely replaced */ + { + if (!WEB_IS_REPLACEMENT(join_key)) /* this is the first site */ + { + /* the close date of the first site needs to align on a revision + * boundary */ + res -= pWS->nParam * nSiteDuration / 2; + } + } + break; + case WEB_REC_START_DATE_ID: + strtodt(&dSiteOpen, DATE_MINIMUM); + res = dSiteOpen.julian - + (((join_key - 1) * WEB_DATE_STAGGER) % nSiteDuration / 2); + res += (join_key % pWS->nParam) * nSiteDuration; + break; + case WEB_REC_END_DATE_ID: + strtodt(&dSiteOpen, DATE_MINIMUM); + res = dSiteOpen.julian - + ((join_key * WEB_DATE_STAGGER) % nSiteDuration / 2); + res += ((join_key + 1) % pWS->nParam) * nSiteDuration * 5 - 1; + break; + case WP_REC_START_DATE_ID: + strtodt(&dSiteOpen, DATE_MINIMUM); + res = dSiteOpen.julian - + (((join_key - 1) * WEB_DATE_STAGGER) % nSiteDuration / 2); + res += (join_key % pWP->nParam) * nSiteDuration * 5; + break; + case WP_REC_END_DATE_ID: + strtodt(&dSiteOpen, DATE_MINIMUM); + res = dSiteOpen.julian - + ((join_key * WEB_DATE_STAGGER) % nSiteDuration / 2); + res += ((join_key + 1) % pWP->nParam) * nSiteDuration - 1; + break; + case WP_CREATION_DATE_SK: + /* page creation has to happen outside of the page window, to assure a + * constant number of pages, so it occurs in the gap between site + * creation and the site's actual activity. For sites that are replaced + * in the time span of the data set, this will depend on whether they + * are the first version or the second + */ + strtodt(&dSiteOpen, DATE_MINIMUM); + kSite = join_key / WEB_PAGES_PER_SITE + 1; + res = dSiteOpen.julian - + ((static_cast(kSite) * WEB_DATE_STAGGER) % nSiteDuration / 2); + if ((static_cast(kSite) % pWP->nParam) == + 0) /* this is a site that gets replaced */ + { + genrand_integer( + &nTemp, + DIST_UNIFORM, + static_cast(res), + dSiteOpen.julian, + 0, + col, + dsdGenContext); + res = nTemp; + } + break; + /***************** + * join key from here on is a date for which a valid site/page must be + * found the sk for a web page is a compound value: + * and each component is a combination of the unique site or page and + * the active revision to it + */ + case WR_WEB_PAGE_SK: + case WS_WEB_PAGE_SK: + res = genrand_integer( + NULL, DIST_UNIFORM, 1, WEB_PAGES_PER_SITE, 0, col, dsdGenContext); + break; + } + + return (res); +} + +/* + * Routine: mk_join(int from_tbl, int to_tbl, int join_count) + * Purpose: return a primary key for to_tbl, creating a join between from_tbl + *and to_tbl Algorithm: all joins are currently uniformly distributed. The + *calling convention allows for each join in the schema to be distributed + *differently Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: Relies on existing RNG code, which isn't really 64bit; will probably + *requre a rework of the genrand_xx routines + */ +ds_key_t mk_join( + int from_col, + int to_tbl, + ds_key_t join_count, + DSDGenContext& dsdGenContext) { + ds_key_t res; + int nYear, nFromTable = 0, nTableIndex = to_tbl; + tdef* pTdef; + + nFromTable = getTableFromColumn(from_col, dsdGenContext); + + /* + * if the table being joined to employs sparse keys, the join gets handled + * in sparse.c + */ + pTdef = getSimpleTdefsByNumber(to_tbl, dsdGenContext); + if (pTdef->flags & FL_SPARSE) { + if (pTdef->arSparseKeys == NULL) + initSparseKeys(to_tbl, dsdGenContext); + } + + switch (to_tbl) { + /* some tables require special handling */ + case CATALOG_PAGE: + return (cp_join(nFromTable, from_col, join_count, dsdGenContext)); + case DATET: + genrand_integer( + &nYear, + DIST_UNIFORM, + YEAR_MINIMUM, + YEAR_MAXIMUM, + 0, + from_col, + dsdGenContext); + return ( + date_join(nFromTable, from_col, join_count, nYear, dsdGenContext)); + case TIME: + return (time_join(nFromTable, from_col, join_count, dsdGenContext)); + /* the rest of the tables use standard, uniform joins */ + default: + /* + * all TYPE2 tables (i.e., history keeping dimensions) need a special + * join algorithm + */ + if (pTdef->flags & FL_TYPE_2) + return (scd_join(nTableIndex, from_col, join_count, dsdGenContext)); + + if (pTdef->flags & FL_SPARSE) + return (randomSparseKey(nTableIndex, from_col, dsdGenContext)); + + genrand_key( + &res, + DIST_UNIFORM, + static_cast(1), + get_rowcount(nTableIndex, dsdGenContext), + static_cast(0), + from_col, + dsdGenContext); + break; + } + + return (static_cast(res)); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/list.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/list.cpp new file mode 100644 index 0000000000000..f6d69e8d2a4c0 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/list.cpp @@ -0,0 +1,272 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "list.h" +#include +#include +#include +#include "config.h" +#include "error_msg.h" +#include "porting.h" + +list_t* makeList(int nFlags, int (*SortFunc)(const void* d1, const void* d2)) { + auto pRes = static_cast(malloc(sizeof(list_t))); + MALLOC_CHECK(pRes); + if (pRes == nullptr) + ReportError(QERR_NO_MEMORY, "client list", 1); + memset(pRes, 0, sizeof(list_t)); + pRes->nFlags = nFlags; + pRes->pSortFunc = SortFunc; + + return (pRes); +} + +list_t* addList(list_t* pList, void* pData) { + node_t* pInsertPoint; + unsigned int bMoveForward = + (static_cast(pList->nFlags) & L_FL_HEAD); + + auto pNode = static_cast(malloc(sizeof(node_t))); + MALLOC_CHECK(pNode); + if (!pNode) + ReportErrorNoLine(QERR_NO_MEMORY, "client node", 1); + memset(pNode, 0, sizeof(node_t)); + pNode->pData = pData; + + if (pList->nMembers == 0) /* first node */ + { + pList->head = pNode; + pList->tail = pNode; + pList->nMembers = 1; + return (pList); + } + + if (static_cast(pList->nFlags) & L_FL_SORT) { + if (pList->pSortFunc(pData, pList->head->pData) <= 0) { + /* new node become list head */ + pNode->pNext = pList->head; + pList->head->pPrev = pNode; + pList->head = pNode; + pList->nMembers += 1; + return (pList); + } + pInsertPoint = pList->head; + + /* find the correct point to insert new node */ + while (pInsertPoint) { + if (pList->pSortFunc(pInsertPoint->pData, pData) < 0) + break; + pInsertPoint = (bMoveForward) ? pInsertPoint->pNext : pInsertPoint->pPrev; + } + if (pInsertPoint) /* mid-list insert */ + { + pNode->pNext = pInsertPoint->pNext; + pNode->pPrev = pInsertPoint; + pInsertPoint->pNext = pNode; + } else { + if (bMoveForward) { + /* new node becomes list tail */ + pNode->pPrev = pList->tail; + pList->tail->pNext = pNode; + pList->tail = pNode; + } else { + /* new node become list head */ + pNode->pNext = pList->head; + pList->head->pPrev = pNode; + pList->head = pNode; + } + } + + pList->nMembers += 1; + + return (pList); + } + + if (static_cast(pList->nFlags) & L_FL_HEAD) { + pNode->pNext = pList->head; + pList->head->pPrev = pNode; + pList->head = pNode; + pList->nMembers += 1; + } else { + pNode->pPrev = pList->tail; + pList->tail->pNext = pNode; + pList->tail = pNode; + pList->nMembers += 1; + } + + return (pList); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void* removeItem(list_t* pList, int bHead) { + void* pResult; + + if (pList->nMembers == 0) + return (NULL); + + if (!bHead) { + pResult = pList->tail->pData; + pList->tail = pList->tail->pPrev; + pList->tail->pNext = NULL; + } else { + pResult = pList->head->pData; + pList->head = pList->head->pNext; + pList->head->pPrev = NULL; + } + + pList->nMembers -= 1; + + return (pResult); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void* getHead(list_t* pList) { + assert(pList); + + if (!pList->head) + return (NULL); + + pList->pCurrent = pList->head; + + return (pList->pCurrent->pData); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void* getTail(list_t* pList) { + assert(pList); + + if (!pList->tail) + return (NULL); + + pList->pCurrent = pList->tail; + + return (pList->pCurrent->pData); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void* getNext(list_t* pList) { + assert(pList); + + if (!pList->pCurrent->pNext) + return (NULL); + + pList->pCurrent = pList->pCurrent->pNext; + + return (pList->pCurrent->pData); +} + +/* + * Routine: + * Purpose: findList(list_t *pList, void *pData) + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void* findList(list_t* pList, void* pData) { + void* pNode; + struct LIST_NODE_T* pOldCurrent = pList->pCurrent; + + for (pNode = getHead(pList); pNode; pNode = getNext(pList)) + if (pList->pSortFunc(pNode, pData) == 0) { + pList->pCurrent = pOldCurrent; + return (pNode); + } + + pList->pCurrent = pOldCurrent; + return (NULL); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void* getItem(list_t* pList, int nIndex) { + void* pResult; + struct LIST_NODE_T* pOldCurrent = pList->pCurrent; + + if (nIndex > length(pList)) + return (NULL); + + for (pResult = getHead(pList); --nIndex; pResult = getNext(pList)) + ; + + pList->pCurrent = pOldCurrent; + return (pResult); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/load.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/load.cpp new file mode 100644 index 0000000000000..8390d6d763ab7 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/load.cpp @@ -0,0 +1,87 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "config.h" +#include "porting.h" +#include "tables.h" + +#ifdef SQLSERVER +// ODBC headers +#include +#include +#include +SQLHENV henv; +#endif + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int create_table(int nTable) { + return (0); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void load_init(void) + +{ +#ifdef SQLSERVER + SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); + SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); +#endif + + return; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void load_close(void) { +#ifdef SQLSERVER + SQLFreeHandle(SQL_HANDLE_ENV, henv); +#endif + + return; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/misc.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/misc.cpp new file mode 100644 index 0000000000000..8ec2c59635ad7 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/misc.cpp @@ -0,0 +1,103 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "porting.h" +#ifndef USE_STDLIB_H +#include +#endif +#include +#ifdef AIX +#include +#endif /* AIX */ +#include +#include +#include "date.h" +#include "decimal.h" +#include "dist.h" +#include "genrand.h" +#include "misc.h" +#include "r_params.h" +#include "tdefs.h" + +static char* alpha_num = + "0123456789abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ,"; + +char* getenv(const char* name); +int print_separator(int sep); + +extern long Seed[]; + +#ifdef WIN32 +#define PATH_SEP '\\' +#else +#define PATH_SEP '/' +#endif + +int file_num = -1; + +/* + * + * Various routines that handle distributions, value selections and + * seed value management for the DSS benchmark. Current functions: + * env_config -- set config vars with optional environment override + * a_rnd(min, max) -- random alphanumeric within length range + */ + +/* + * env_config: look for a environmental variable setting and return its + * value; otherwise return the default supplied + */ +char* env_config(char* var, char* dflt) { + static char* evar; + + if ((evar = getenv(var)) != NULL) + return (evar); + else + return (dflt); +} + +/* + * generate a random string with length randomly selected in [min, max] + * and using the characters in alphanum (currently includes a space + * and comma) + */ +int a_rnd( + int min, + int max, + int column, + char* dest, + DSDGenContext& dsdGenContext) { + int i, len, char_int; + + genrand_integer(&len, DIST_UNIFORM, min, max, 0, column, dsdGenContext); + for (i = 0; i < len; i++) { + if (i % 5 == 0) + genrand_integer( + &char_int, + DIST_UNIFORM, + 0, + static_cast(1) << 30, + 0, + column, + dsdGenContext); + *(dest + i) = alpha_num[static_cast(char_int) & 077]; + char_int = static_cast(static_cast(char_int) >> 6); + } + *(dest + len) = '\0'; + return (len); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/nulls.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/nulls.cpp new file mode 100644 index 0000000000000..e5cab55be7147 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/nulls.cpp @@ -0,0 +1,84 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "nulls.h" +#include "config.h" +#include "genrand.h" +#include "porting.h" +#include "tdefs.h" + +/* + * Routine: nullCheck(int nColumn, DSDGenContext& dsdGenContext) + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int nullCheck(int nColumn, DSDGenContext& dsdGenContext) { + int nLastTable = 0; + tdef* pTdef; + ds_key_t kBitMask = 1; + + nLastTable = getTableFromColumn(nColumn, dsdGenContext); + pTdef = getSimpleTdefsByNumber(nLastTable, dsdGenContext); + + kBitMask <<= nColumn - pTdef->nFirstColumn; + + return ((pTdef->kNullBitMap & kBitMask) != 0); +} + +/* +* Routine: nullSet(int *pDest, int nStream, DSDGenContext& dsdGenContext) +* Purpose: set the kNullBitMap for a particular table +* Algorithm: +* 1. if random[1,100] >= table's NULL pct, clear map and return +* 2. set map + +* Data Structures: +* +* Params: +* Returns: +* Called By: +* Calls: +* Assumptions: +* Side Effects: uses 2 RNG calls +* TODO: None +*/ +void nullSet(ds_key_t* pDest, int nStream, DSDGenContext& dsdGenContext) { + int nThreshold; + ds_key_t kBitMap; + int nLastTable = 0; + tdef* pTdef; + + nLastTable = getTableFromColumn(nStream, dsdGenContext); + pTdef = getSimpleTdefsByNumber(nLastTable, dsdGenContext); + + /* burn the RNG calls */ + genrand_integer( + &nThreshold, DIST_UNIFORM, 0, 9999, 0, nStream, dsdGenContext); + genrand_key(&kBitMap, DIST_UNIFORM, 1, MAXINT, 0, nStream, dsdGenContext); + + /* set the bitmap based on threshold and NOT NULL definitions */ + *pDest = 0; + if (nThreshold < pTdef->nNullPct) { + *pDest = kBitMap; + *pDest &= ~pTdef->kNotNullBitMap; + } + + return; +} \ No newline at end of file diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/parallel.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/parallel.cpp new file mode 100644 index 0000000000000..da16606ee2bfe --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/parallel.cpp @@ -0,0 +1,198 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include +#include "config.h" +#include "genrand.h" +#include "porting.h" +#include "r_params.h" +#include "scaling.h" +#include "tdefs.h" + +/* + * Routine: split_work(int tnum, worker_t *w) + * Purpose: allocate work between processes and threads + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int split_work( + int tnum, + ds_key_t* pkFirstRow, + ds_key_t* pkRowCount, + DSDGenContext& dsdGenContext) { + ds_key_t kTotalRows, kRowsetSize, kExtraRows; + int nParallel, nChild; + + kTotalRows = get_rowcount(tnum, dsdGenContext); + nParallel = get_int("PARALLEL", dsdGenContext); + nChild = get_int("CHILD", dsdGenContext) + 1; + + /* + * 1. small tables aren't paralelized + * 2. nothing is parallelized unless a command line arg is supplied + */ + *pkFirstRow = 1; + *pkRowCount = kTotalRows; + + if (kTotalRows < 1000000) { + if (nChild > 1) /* small table; only build it once */ + { + *pkFirstRow = 1; + *pkRowCount = 0; + return (0); + } + return (1); + } + + if (!is_set("PARALLEL", dsdGenContext)) { + return (1); + } + + /* + * at this point, do the calculation to set the rowcount for this part of a + * parallel build + */ + kExtraRows = kTotalRows % nParallel; + kRowsetSize = (kTotalRows - kExtraRows) / nParallel; + + /* start the starting row id */ + *pkFirstRow += (nChild - 1) * kRowsetSize; + if (kExtraRows && (nChild - 1)) + *pkFirstRow += ((nChild - 1) < kExtraRows) ? (nChild - 1) : kExtraRows; + + /* set the rowcount for this child */ + *pkRowCount = kRowsetSize; + if (kExtraRows && (nChild <= kExtraRows)) + *pkRowCount += 1; + + return (1); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int checkSeeds(tdef* pTdef, DSDGenContext& dsdGenContext) { + int i, res, nReturnCode = 0; + static int bSetSeeds = 0; + + if (!dsdGenContext.checkSeeds_init) { + bSetSeeds = is_set("CHKSEEDS", dsdGenContext); + dsdGenContext.checkSeeds_init = 1; + } + + for (i = pTdef->nFirstColumn; i <= pTdef->nLastColumn; i++) { + while (dsdGenContext.Streams[i].nUsed < + dsdGenContext.Streams[i].nUsedPerRow) + genrand_integer(&res, DIST_UNIFORM, 1, 100, 0, i, dsdGenContext); + if (bSetSeeds) { + if (dsdGenContext.Streams[i].nUsed > + dsdGenContext.Streams[i].nUsedPerRow) { + fprintf( + stderr, + "Seed overrun on column %d. Used: %d\n", + i, + dsdGenContext.Streams[i].nUsed); + dsdGenContext.Streams[i].nUsedPerRow = dsdGenContext.Streams[i].nUsed; + nReturnCode = 1; + } + } + dsdGenContext.Streams[i].nUsed = 0; /* reset for the next time */ + } + + return (nReturnCode); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int row_stop(int tbl, DSDGenContext& dsdGenContext) { + tdef* pTdef; + + pTdef = getSimpleTdefsByNumber(tbl, dsdGenContext); + checkSeeds(pTdef, dsdGenContext); + if (pTdef->flags & FL_PARENT) { + pTdef = getSimpleTdefsByNumber(pTdef->nParam, dsdGenContext); + checkSeeds(pTdef, dsdGenContext); + } + return (0); +} + +/* + * Routine: row_skip + * Purpose: skip over un-used rows in a table + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: 20020816 jms The second parameter should really be a ds_key_t to allow + * BIG skips + */ +int row_skip(int tbl, ds_key_t count, DSDGenContext& dsdGenContext) { + int i; + for (i = 0; dsdGenContext.Streams[i].nColumn != -1; i++) { + if (dsdGenContext.Streams[i].nTable == tbl) { + skip_random( + i, count * dsdGenContext.Streams[i].nUsedPerRow, dsdGenContext); + dsdGenContext.Streams[i].nUsed = 0; + dsdGenContext.Streams[i].nTotal = + count * dsdGenContext.Streams[i].nUsedPerRow; + } + if (dsdGenContext.Streams[i].nDuplicateOf && + (dsdGenContext.Streams[i].nDuplicateOf != i)) { + skip_random( + dsdGenContext.Streams[i].nDuplicateOf, + count * + dsdGenContext.Streams[dsdGenContext.Streams[i].nDuplicateOf] + .nUsedPerRow, + dsdGenContext); + dsdGenContext.Streams[dsdGenContext.Streams[i].nDuplicateOf].nUsed = 0; + dsdGenContext.Streams[dsdGenContext.Streams[i].nDuplicateOf].nTotal = + count * dsdGenContext.Streams[i].nUsedPerRow; + } + } + + return (0); +} \ No newline at end of file diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/permute.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/permute.cpp new file mode 100644 index 0000000000000..0ca880a434205 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/permute.cpp @@ -0,0 +1,103 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "config.h" +#include "porting.h" +#ifndef USE_STDLIB_H +#include +#endif +#include +#include "genrand.h" + +/* + * Routine: MakePermutation(int nSize) + * Purpose: Permute the integers in [1..nSize] + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int* makePermutation( + int* nNumberSet, + int nSize, + int nStream, + DSDGenContext& dsdGenContext) { + int i, nTemp, nIndex, *pInt; + + if (nSize <= 0) + return (NULL); + + if (!nNumberSet) { + nNumberSet = static_cast(malloc(nSize * sizeof(int))); + MALLOC_CHECK(nNumberSet); + pInt = nNumberSet; + for (i = 0; i < nSize; i++) + *pInt++ = i; + } + + for (i = 0; i < nSize; i++) { + nIndex = genrand_integer( + NULL, DIST_UNIFORM, 0, nSize - 1, 0, nStream, dsdGenContext); + nTemp = nNumberSet[i]; + nNumberSet[i] = nNumberSet[nIndex]; + nNumberSet[nIndex] = nTemp; + } + + return (nNumberSet); +} + +/* + * Routine: MakePermutation(int nSize) + * Purpose: Permute the integers in [1..nSize] + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t* makeKeyPermutation( + ds_key_t* nNumberSet, + ds_key_t nSize, + int nStream, + DSDGenContext& dsdGenContext) { + ds_key_t i, nTemp, nIndex, *pInt; + if (nSize <= 0) + return (NULL); + + if (!nNumberSet) { + nNumberSet = static_cast(malloc(nSize * sizeof(ds_key_t))); + MALLOC_CHECK(nNumberSet); + pInt = nNumberSet; + for (i = 0; i < nSize; i++) + *pInt++ = i; + } + + for (i = 0; i < nSize; i++) { + nIndex = genrand_key( + NULL, DIST_UNIFORM, 0, nSize - 1, 0, nStream, dsdGenContext); + nTemp = nNumberSet[i]; + nNumberSet[i] = nNumberSet[nIndex]; + nNumberSet[nIndex] = nTemp; + } + + return (nNumberSet); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/pricing.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/pricing.cpp new file mode 100644 index 0000000000000..37af73e46f7bb --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/pricing.cpp @@ -0,0 +1,459 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "pricing.h" +#include +#include "columns.h" +#include "config.h" +#include "constants.h" +#include "decimal.h" +#include "dist.h" +#include "error_msg.h" +#include "genrand.h" +#include "porting.h" +#include "w_web_sales.h" + +#define MAX_LIMIT 12 +static ds_limits_t aPriceLimits[MAX_LIMIT] = { + {CS_PRICING, + CS_QUANTITY_MAX, + CS_MARKUP_MAX, + CS_DISCOUNT_MAX, + CS_WHOLESALE_MAX, + CS_COUPON_MAX}, + {SS_PRICING, + SS_QUANTITY_MAX, + SS_MARKUP_MAX, + SS_DISCOUNT_MAX, + SS_WHOLESALE_MAX, + SS_COUPON_MAX}, + {WS_PRICING, + WS_QUANTITY_MAX, + WS_MARKUP_MAX, + WS_DISCOUNT_MAX, + WS_WHOLESALE_MAX, + WS_COUPON_MAX}, + {CR_PRICING, + CS_QUANTITY_MAX, + CS_MARKUP_MAX, + CS_DISCOUNT_MAX, + CS_WHOLESALE_MAX, + CS_COUPON_MAX}, + {SR_PRICING, + SS_QUANTITY_MAX, + SS_MARKUP_MAX, + SS_DISCOUNT_MAX, + SS_WHOLESALE_MAX, + SS_COUPON_MAX}, + {WR_PRICING, + WS_QUANTITY_MAX, + WS_MARKUP_MAX, + WS_DISCOUNT_MAX, + WS_WHOLESALE_MAX, + WS_COUPON_MAX}, + {S_PLINE_PRICING, + WS_QUANTITY_MAX, + WS_MARKUP_MAX, + WS_DISCOUNT_MAX, + WS_WHOLESALE_MAX, + WS_COUPON_MAX}, + {S_CLIN_PRICING, + WS_QUANTITY_MAX, + WS_MARKUP_MAX, + WS_DISCOUNT_MAX, + WS_WHOLESALE_MAX, + WS_COUPON_MAX}, + {S_WLIN_PRICING, + WS_QUANTITY_MAX, + WS_MARKUP_MAX, + WS_DISCOUNT_MAX, + WS_WHOLESALE_MAX, + WS_COUPON_MAX}, + {S_SRET_PRICING, + WS_QUANTITY_MAX, + WS_MARKUP_MAX, + WS_DISCOUNT_MAX, + WS_WHOLESALE_MAX, + WS_COUPON_MAX}, + {S_CRET_PRICING, + WS_QUANTITY_MAX, + WS_MARKUP_MAX, + WS_DISCOUNT_MAX, + WS_WHOLESALE_MAX, + WS_COUPON_MAX}, + {S_WRET_PRICING, + WS_QUANTITY_MAX, + WS_MARKUP_MAX, + WS_DISCOUNT_MAX, + WS_WHOLESALE_MAX, + WS_COUPON_MAX} + +}; + +/* + * Routine: set_pricing(int nTabId, ds_pricing_t *pPricing) + * Purpose: handle the various pricing calculations for the fact tables + * Notes: + * the RNG usage is not kept in sync between sales pricing and returns + *pricing. If the calculations look wrong, it may be necessary to "waste" some + *RNG calls on one side or the other to bring things back in line Data + *Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void set_pricing( + int nTabId, + ds_pricing_t* pPricing, + DSDGenContext& dsdGenContext) { + int nLastId = -1, nQuantityMax = std::numeric_limits::max(), + nQuantityMin = 1; + decimal_t dQuantity, dMarkupMin, dDiscountMin, dWholesaleMin, dMarkupMax, + dDiscountMax, dWholesaleMax, dCouponMin, dCouponMax, dZero, dOneHalf, + d9pct, dOne, dTemp, dHundred; + decimal_t dMarkup, dCoupon, dShipping, dDiscount, dTemp2; + int i, nCashPct, nCreditPct, nCouponUsage; + + strtodec(&dMarkupMin, "0.00"); + strtodec(&dDiscountMin, "0.00"); + strtodec(&dWholesaleMin, "1.00"); + strtodec(&dCouponMin, "0.00"); + strtodec(&dZero, "0.00"); + strtodec(&dOneHalf, "0.50"); + strtodec(&d9pct, "0.09"); + strtodec(&dWholesaleMin, "1.00"); + strtodec(&dHundred, "100.00"); + strtodec(&dOne, "1.00"); + + if (nTabId != nLastId) { + nLastId = -1; + for (i = 0; i < MAX_LIMIT; i++) { + if (nTabId == aPriceLimits[i].nId) + nLastId = i; + } + if (nLastId == -1) + INTERNAL("No pricing limits defined"); + nQuantityMax = atoi(aPriceLimits[nLastId].szQuantity); + strtodec(&dDiscountMax, aPriceLimits[nLastId].szDiscount); + strtodec(&dMarkupMax, aPriceLimits[nLastId].szMarkUp); + strtodec(&dWholesaleMax, aPriceLimits[nLastId].szWholesale); + strtodec(&dCouponMax, aPriceLimits[nLastId].szCoupon); + } + + switch (nTabId) { + case SS_PRICING: + case CS_PRICING: + case WS_PRICING: + case S_PLINE_PRICING: + case S_CLIN_PRICING: + case S_WLIN_PRICING: + genrand_integer( + &pPricing->quantity, + DIST_UNIFORM, + nQuantityMin, + nQuantityMax, + 0, + nTabId, + dsdGenContext); + itodec(&dQuantity, pPricing->quantity); + genrand_decimal( + &pPricing->wholesale_cost, + DIST_UNIFORM, + &dWholesaleMin, + &dWholesaleMax, + NULL, + nTabId, + dsdGenContext); + + /* ext_wholesale_cost = wholesale_cost * quantity */ + decimal_t_op( + &pPricing->ext_wholesale_cost, + OP_MULT, + &dQuantity, + &pPricing->wholesale_cost); + + /* list_price = wholesale_cost * (1 + markup) */ + genrand_decimal( + &dMarkup, + DIST_UNIFORM, + &dMarkupMin, + &dMarkupMax, + NULL, + nTabId, + dsdGenContext); + decimal_t_op(&dMarkup, OP_PLUS, &dMarkup, &dOne); + decimal_t_op( + &pPricing->list_price, OP_MULT, &pPricing->wholesale_cost, &dMarkup); + + /* sales_price = list_price * (1 - discount)*/ + genrand_decimal( + &dDiscount, + DIST_UNIFORM, + &dDiscountMin, + &dDiscountMax, + NULL, + nTabId, + dsdGenContext); + NegateDecimal(&dDiscount); + decimal_t_op(&pPricing->ext_discount_amt, OP_PLUS, &dDiscount, &dOne); + decimal_t_op( + &pPricing->sales_price, + OP_MULT, + &pPricing->list_price, + &pPricing->ext_discount_amt); + + /* ext_list_price = list_price * quantity */ + decimal_t_op( + &pPricing->ext_list_price, + OP_MULT, + &pPricing->list_price, + &dQuantity); + + /* ext_sales_price = sales_price * quantity */ + decimal_t_op( + &pPricing->ext_sales_price, + OP_MULT, + &pPricing->sales_price, + &dQuantity); + + /* ext_discount_amt = ext_list_price - ext_sales_price */ + decimal_t_op( + &pPricing->ext_discount_amt, + OP_MINUS, + &pPricing->ext_list_price, + &pPricing->ext_sales_price); + + /* coupon_amt = ext_sales_price * coupon */ + genrand_decimal( + &dCoupon, DIST_UNIFORM, &dZero, &dOne, NULL, nTabId, dsdGenContext); + genrand_integer( + &nCouponUsage, DIST_UNIFORM, 1, 100, 0, nTabId, dsdGenContext); + if (nCouponUsage <= 20) /* 20% of sales employ a coupon */ + decimal_t_op( + &pPricing->coupon_amt, + OP_MULT, + &pPricing->ext_sales_price, + &dCoupon); + else + memcpy(&pPricing->coupon_amt, &dZero, sizeof(decimal_t)); + + /* net_paid = ext_sales_price - coupon_amt */ + decimal_t_op( + &pPricing->net_paid, + OP_MINUS, + &pPricing->ext_sales_price, + &pPricing->coupon_amt); + + /* shipping_cost = list_price * shipping */ + genrand_decimal( + &dShipping, + DIST_UNIFORM, + &dZero, + &dOneHalf, + NULL, + nTabId, + dsdGenContext); + decimal_t_op( + &pPricing->ship_cost, OP_MULT, &pPricing->list_price, &dShipping); + + /* ext_shipping_cost = shipping_cost * quantity */ + decimal_t_op( + &pPricing->ext_ship_cost, OP_MULT, &pPricing->ship_cost, &dQuantity); + + /* net_paid_inc_ship = net_paid + ext_shipping_cost */ + decimal_t_op( + &pPricing->net_paid_inc_ship, + OP_PLUS, + &pPricing->net_paid, + &pPricing->ext_ship_cost); + + /* ext_tax = tax * net_paid */ + genrand_decimal( + &pPricing->tax_pct, + DIST_UNIFORM, + &dZero, + &d9pct, + NULL, + nTabId, + dsdGenContext); + decimal_t_op( + &pPricing->ext_tax, OP_MULT, &pPricing->net_paid, &pPricing->tax_pct); + + /* net_paid_inc_tax = net_paid + ext_tax */ + decimal_t_op( + &pPricing->net_paid_inc_tax, + OP_PLUS, + &pPricing->net_paid, + &pPricing->ext_tax); + + /* net_paid_inc_ship_tax = net_paid_inc_tax + ext_shipping_cost */ + decimal_t_op( + &pPricing->net_paid_inc_ship_tax, + OP_PLUS, + &pPricing->net_paid_inc_ship, + &pPricing->ext_tax); + + /* net_profit = net_paid - ext_wholesale_cost */ + decimal_t_op( + &pPricing->net_profit, + OP_MINUS, + &pPricing->net_paid, + &pPricing->ext_wholesale_cost); + break; + case CR_PRICING: + case SR_PRICING: + case WR_PRICING: + /* quantity is determined before we are called */ + /* ext_wholesale_cost = wholesale_cost * quantity */ + itodec(&dQuantity, pPricing->quantity); + decimal_t_op( + &pPricing->ext_wholesale_cost, + OP_MULT, + &dQuantity, + &pPricing->wholesale_cost); + + /* ext_list_price = list_price * quantity */ + decimal_t_op( + &pPricing->ext_list_price, + OP_MULT, + &pPricing->list_price, + &dQuantity); + + /* ext_sales_price = sales_price * quantity */ + decimal_t_op( + &pPricing->ext_sales_price, + OP_MULT, + &pPricing->sales_price, + &dQuantity); + + /* net_paid = ext_list_price (couppons don't effect returns) */ + memcpy( + &pPricing->net_paid, &pPricing->ext_sales_price, sizeof(decimal_t)); + + /* shipping_cost = list_price * shipping */ + genrand_decimal( + &dShipping, + DIST_UNIFORM, + &dZero, + &dOneHalf, + NULL, + nTabId, + dsdGenContext); + decimal_t_op( + &pPricing->ship_cost, OP_MULT, &pPricing->list_price, &dShipping); + + /* ext_shipping_cost = shipping_cost * quantity */ + decimal_t_op( + &pPricing->ext_ship_cost, OP_MULT, &pPricing->ship_cost, &dQuantity); + + /* net_paid_inc_ship = net_paid + ext_shipping_cost */ + decimal_t_op( + &pPricing->net_paid_inc_ship, + OP_PLUS, + &pPricing->net_paid, + &pPricing->ext_ship_cost); + + /* ext_tax = tax * net_paid */ + decimal_t_op( + &pPricing->ext_tax, OP_MULT, &pPricing->net_paid, &pPricing->tax_pct); + + /* net_paid_inc_tax = net_paid + ext_tax */ + decimal_t_op( + &pPricing->net_paid_inc_tax, + OP_PLUS, + &pPricing->net_paid, + &pPricing->ext_tax); + + /* net_paid_inc_ship_tax = net_paid_inc_tax + ext_shipping_cost */ + decimal_t_op( + &pPricing->net_paid_inc_ship_tax, + OP_PLUS, + &pPricing->net_paid_inc_ship, + &pPricing->ext_tax); + + /* net_profit = net_paid - ext_wholesale_cost */ + decimal_t_op( + &pPricing->net_profit, + OP_MINUS, + &pPricing->net_paid, + &pPricing->ext_wholesale_cost); + + /* see to it that the returned amounts add up to the total returned */ + /* allocate some of return to cash */ + genrand_integer( + &nCashPct, DIST_UNIFORM, 0, 100, 0, nTabId, dsdGenContext); + itodec(&dTemp, nCashPct); + decimal_t_op(&pPricing->refunded_cash, OP_DIV, &dTemp, &dHundred); + decimal_t_op( + &pPricing->refunded_cash, + OP_MULT, + &pPricing->refunded_cash, + &pPricing->net_paid); + + /* allocate some to reversed charges */ + genrand_integer( + &nCreditPct, DIST_UNIFORM, 1, 100, 0, nTabId, dsdGenContext); + itodec(&dTemp2, nCreditPct); + decimal_t_op(&dTemp, OP_DIV, &dTemp2, &dHundred); + decimal_t_op( + &dTemp2, OP_MINUS, &pPricing->net_paid, &pPricing->refunded_cash); + decimal_t_op(&pPricing->reversed_charge, OP_MULT, &dTemp2, &dTemp); + + /* the rest is store credit */ + decimal_t_op( + &pPricing->store_credit, + OP_MINUS, + &pPricing->net_paid, + &pPricing->reversed_charge); + decimal_t_op( + &pPricing->store_credit, + OP_MINUS, + &pPricing->store_credit, + &pPricing->refunded_cash); + + /* pick a fee for the return */ + genrand_decimal( + &pPricing->fee, + DIST_UNIFORM, + &dOneHalf, + &dHundred, + &dZero, + nTabId, + dsdGenContext); + + /* and calculate the net effect */ + decimal_t_op( + &pPricing->net_loss, + OP_MINUS, + &pPricing->net_paid_inc_ship_tax, + &pPricing->store_credit); + decimal_t_op( + &pPricing->net_loss, + OP_MINUS, + &pPricing->net_loss, + &pPricing->refunded_cash); + decimal_t_op( + &pPricing->net_loss, + OP_MINUS, + &pPricing->net_loss, + &pPricing->reversed_charge); + decimal_t_op( + &pPricing->net_loss, OP_PLUS, &pPricing->net_loss, &pPricing->fee); + break; + } + + return; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/r_params.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/r_params.cpp new file mode 100644 index 0000000000000..4647569f675fc --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/r_params.cpp @@ -0,0 +1,707 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +/* + * parameter handling functions + */ +#include "r_params.h" +#include +#include +#include +#include +#include +#include "config.h" +#include "dist.h" +#include "porting.h" +#include "tdefs.h" + +#define PARAM_MAX_LEN 80 +#define MAX_LINE_LEN 120 +#ifdef WIN32 +#define OPTION_START '/' +#else +#define OPTION_START '-' +#endif + +#ifndef TEST +extern option_t options[]; +extern char* params[]; +#else +option_t options[] = { + {"PROG", OPT_STR | OPT_HIDE, 0, NULL, NULL, "tester"}, + {"PARAMS", OPT_STR, 1, "read parameters from file ", read_file, ""}, + {"DISTRIBUTIONS", + OPT_STR, + 2, + "read distributions from file ", + NULL, + "tester_dist.idx"}, + {"OUTDIR", OPT_STR, 3, "generate files in directory ", NULL, "./"}, + {"VERBOSE", OPT_FLG, 4, "enable verbose output", NULL, "N"}, + {"HELP", OPT_FLG, 5, "display this message", usage, "N"}, + {"scale", OPT_INT, 6, "set scale to ", NULL, "1"}, + NULL}; +char* params[9]; +#endif + +int read_file(const char* param_name, const char* option); +int fnd_param(const char* name, DSDGenContext& dsdGenContext); +void print_params(DSDGenContext& dsdGenContext); + +/* + * Routine: load_params() + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20010621 JMS shared memory not yet implemented + */ +void load_params() { + /* + int i=0; + while (options[i].name != NULL) + { + load_param(i, GetSharedMemoryParam(options[i].index)); + i++; + } + SetSharedMemoryStat(STAT_ROWCOUNT, get_int("STEP"), 0); + */ + return; +} + +/* + * Routine: set_flag(int f) + * Purpose: set a toggle parameter + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void set_flg(const char* flag, DSDGenContext& dsdGenContext) { + int nParam; + + init_params(dsdGenContext); + nParam = fnd_param(flag, dsdGenContext); + if (nParam >= 0) + strcpy(dsdGenContext.params[dsdGenContext.options[nParam].index], "Y"); + + return; +} + +/* + * Routine: clr_flg(f) + * Purpose: clear a toggle parameter + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void clr_flg(const char* flag, DSDGenContext& dsdGenContext) { + int nParam; + + init_params(dsdGenContext); + nParam = fnd_param(flag, dsdGenContext); + if (nParam >= 0) + strcpy(dsdGenContext.params[dsdGenContext.options[nParam].index], "N"); + return; +} + +/* + * Routine: is_set(int f) + * Purpose: return the state of a toggle parameter, or whether or not a string + * or int parameter has been set Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int is_set(const char* flag, DSDGenContext& dsdGenContext) { + int nParam, bIsSet = 0; + + init_params(dsdGenContext); + nParam = fnd_param(flag, dsdGenContext); + if (nParam >= 0) { + if ((static_cast(dsdGenContext.options[nParam].flags) & + TYPE_MASK) == OPT_FLG) + bIsSet = + (dsdGenContext.params[dsdGenContext.options[nParam].index][0] == 'Y') + ? 1 + : 0; + else + bIsSet = (static_cast(dsdGenContext.options[nParam].flags) & + OPT_SET) || + (strlen(dsdGenContext.options[nParam].dflt) > 0); + } + + return (bIsSet); /* better a false negative than a false positive ? */ +} + +/* + * Routine: set_int(int var, char *value) + * Purpose: set an integer parameter + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void set_int(const char* var, const char* val, DSDGenContext& dsdGenContext) { + int nParam; + + init_params(dsdGenContext); + nParam = fnd_param(var, dsdGenContext); + if (nParam >= 0) { + strcpy(dsdGenContext.params[dsdGenContext.options[nParam].index], val); + dsdGenContext.options[nParam].flags = static_cast( + static_cast(dsdGenContext.options[nParam].flags) | OPT_SET); + } + return; +} + +/* + * Routine: get_int(char *var) + * Purpose: return the value of an integer parameter + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int get_int(const char* var, DSDGenContext& dsdGenContext) { + int nParam; + + init_params(dsdGenContext); + nParam = fnd_param(var, dsdGenContext); + if (nParam >= 0) + return (atoi(dsdGenContext.params[dsdGenContext.options[nParam].index])); + else + return (0); +} + +double get_dbl(const char* var, DSDGenContext& dsdGenContext) { + int nParam; + + init_params(dsdGenContext); + nParam = fnd_param(var, dsdGenContext); + if (nParam >= 0) + return (atof(dsdGenContext.params[dsdGenContext.options[nParam].index])); + else + return (0); +} + +/* + * Routine: set_str(int var, char *value) + * Purpose: set a character parameter + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void set_str(const char* var, const char* val, DSDGenContext& dsdGenContext) { + int nParam; + + init_params(dsdGenContext); + nParam = fnd_param(var, dsdGenContext); + if (nParam >= 0) { + strcpy(dsdGenContext.params[dsdGenContext.options[nParam].index], val); + dsdGenContext.options[nParam].flags = static_cast( + static_cast(dsdGenContext.options[nParam].flags) | OPT_SET); + } + + return; +} + +/* + * Routine: get_str(char * var) + * Purpose: return the value of a character parameter + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +char* get_str(const char* var, DSDGenContext& dsdGenContext) { + int nParam; + + init_params(dsdGenContext); + nParam = fnd_param(var, dsdGenContext); + if (nParam >= 0) + return (dsdGenContext.params[dsdGenContext.options[nParam].index]); + else + return (NULL); +} + +/* + * Routine: init_params(DSDGenContext& dsdGenContext) + * Purpose: initialize a parameter set, setting default values + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int init_params(DSDGenContext& dsdGenContext) { + int i; + + if (dsdGenContext.init_params_init) + return (0); + + for (i = 0; dsdGenContext.options[i].name != NULL; i++) { + dsdGenContext.params[dsdGenContext.options[i].index] = + static_cast(malloc(PARAM_MAX_LEN * sizeof(char))); + MALLOC_CHECK(dsdGenContext.params[dsdGenContext.options[i].index]); + strncpy( + dsdGenContext.params[dsdGenContext.options[i].index], + dsdGenContext.options[i].dflt, + 80); + if (*dsdGenContext.options[i].dflt) + dsdGenContext.options[i].flags = static_cast( + static_cast(dsdGenContext.options[i].flags) | OPT_DFLT); + } + + dsdGenContext.init_params_init = 1; + + return (0); +} + +/* + * Routine: save_file(char *path) + * Purpose: print a summary of options + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int save_file(const char* path, DSDGenContext& dsdGenContext) { + int i, w_adjust; + FILE* ofp; + time_t timestamp; + + init_params(dsdGenContext); + time(×tamp); + + if ((ofp = fopen(path, "w")) == NULL) + return (-1); + + auto result = fprintf( + ofp, + "--\n-- %s Benchmark Parameter File\n-- Created: %s", + get_str("PROG", dsdGenContext), + ctime(×tamp)); + if (result < 0) + perror("sprintf failed"); + result = fprintf( + ofp, + "--\n-- Each entry is of the form: ' = -- " + "optional comment'\n"); + if (result < 0) + perror("sprintf failed"); + result = fprintf( + ofp, "-- Refer to benchmark documentation for more details\n--\n"); + if (result < 0) + perror("sprintf failed"); + + for (i = 0; dsdGenContext.options[i].name != NULL; i++) { + if (static_cast(dsdGenContext.options[i].flags) & + OPT_HIDE) /* hidden option */ + continue; + if (strlen(dsdGenContext.params[dsdGenContext.options[i].index]) == 0) + continue; + + result = fprintf(ofp, "%s = ", dsdGenContext.options[i].name); + if (result < 0) + perror("sprintf failed"); + w_adjust = strlen(dsdGenContext.options[i].name) + 3; + if (static_cast(dsdGenContext.options[i].flags) & OPT_STR) { + result = fprintf( + ofp, "\"%s\"", dsdGenContext.params[dsdGenContext.options[i].index]); + if (result < 0) + perror("sprintf failed"); + w_adjust += 2; + } else { + result = fprintf( + ofp, "%s", dsdGenContext.params[dsdGenContext.options[i].index]); + if (result < 0) + perror("sprintf failed"); + } + w_adjust += + strlen(dsdGenContext.params[dsdGenContext.options[i].index]) + 3; + w_adjust = 60 - w_adjust; + result = + fprintf(ofp, "%*s-- %s", w_adjust, " ", dsdGenContext.options[i].usage); + if (result < 0) + perror("sprintf failed"); + if (static_cast(dsdGenContext.options[i].flags) & OPT_NOP) { + result = fprintf(ofp, " NOT IMPLEMENTED"); + if (result < 0) + perror("sprintf failed"); + } + result = fprintf(ofp, "\n"); + if (result < 0) + perror("sprintf failed"); + } + + fclose(ofp); + + return (0); +} + +/* + * Routine: set_option(int var, char *value) + * Purpose: set a particular parameter; main entry point for the module + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int set_option(const char* name, const char* param) { + printf("ERROR: set_option not supported"); + assert(0); + exit(1); +} + +/* + * Routine: process_options(int count, char **vector) + * Purpose: process a set of command line options + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: 20000309 need to return integer to allow processing of left-over args + */ +int process_options( + int count, + const char** vector, + DSDGenContext& dsdGenContext) { + int option_num = 1, res = 1; + + init_params(dsdGenContext); + + while (option_num < count) { + if (*vector[option_num] == OPTION_START) { + if (option_num == (count - 1)) + res = set_option(vector[option_num] + 1, NULL); + else + res = set_option(vector[option_num] + 1, vector[option_num + 1]); + } + + if (res < 0) { + auto result = printf( + "ERROR: option '%s' or its argument unknown.\n", + (vector[option_num] + 1)); + if (result < 0) + perror("sprintf failed"); + usage(NULL, NULL, dsdGenContext); + exit(1); + } else + option_num += res; + } + +#ifdef JMS + if (is_set("VERBOSE", dsdGenContext)) + print_params(dsdGenContext); +#endif + + return (option_num); +} + +/* + * Routine: print_params(DSDGenContext& dsdGenContext) + * Purpose: print a parameter summary to display current settings + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void print_params(DSDGenContext& dsdGenContext) { + int i; + + init_params(dsdGenContext); + + for (i = 0; dsdGenContext.options[i].name != NULL; i++) + if (dsdGenContext.options[i].name != NULL) { + auto result = printf("%s = ", dsdGenContext.options[i].name); + if (result < 0) + perror("sprintf failed"); + switch (static_cast(dsdGenContext.options[i].flags) & + TYPE_MASK) { + case OPT_INT: { + result = printf( + "%d\n", + get_int( + const_cast(dsdGenContext.options[i].name), + dsdGenContext)); + if (result < 0) + perror("sprintf failed"); + break; + } + case OPT_STR: { + result = printf( + "%s\n", + get_str( + const_cast(dsdGenContext.options[i].name), + dsdGenContext)); + if (result < 0) + perror("sprintf failed"); + break; + } + case OPT_FLG: { + result = printf( + "%c\n", + is_set( + const_cast(dsdGenContext.options[i].name), + dsdGenContext) + ? 'Y' + : 'N'); + if (result < 0) + perror("sprintf failed"); + break; + } + } + } + + return; +} + +/* + * Routine: fnd_param(char *name, int *type, char *value, DSDGenContext& + * dsdGenContext) Purpose: traverse the defined parameters, looking for a match + * Algorithm: + * Data Structures: + * + * Params: + * Returns: index of option + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int fnd_param(const char* name, DSDGenContext& dsdGenContext) { + int i, res = -1; + + for (i = 0; dsdGenContext.options[i].name != NULL; i++) { + if (strncasecmp(name, dsdGenContext.options[i].name, strlen(name)) == 0) { + if (res == -1) + res = i; + else + return (-1); + } + } + + return (res); +} + +/* + * Routine: GetParamName(int nParam) + * Purpose: Translate between a parameter index and its name + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +char* GetParamName(int nParam, DSDGenContext& dsdGenContext) { + init_params(dsdGenContext); + + return const_cast(dsdGenContext.options[nParam].name); +} + +/* + * Routine: GetParamValue(int nParam) + * Purpose: Retrieve a parameters string value based on an index + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +char* GetParamValue(int nParam, DSDGenContext& dsdGenContext) { + init_params(dsdGenContext); + + return (dsdGenContext.params[dsdGenContext.options[nParam].index]); +} + +/* + * Routine: load_param(char *szValue, int nParam) + * Purpose: Set a parameter based on an index + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int load_param(int nParam, const char* szValue, DSDGenContext& dsdGenContext) { + init_params(dsdGenContext); + + if (static_cast(dsdGenContext.options[nParam].flags) & + OPT_SET) /* already set from the command line */ + return (0); + else + strcpy(dsdGenContext.params[dsdGenContext.options[nParam].index], szValue); + + return (0); +} + +/* + * Routine: IsIntParam(char *szValue, int nParam) + * Purpose: Boolean test for integer parameter + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int IsIntParam(const char* szParam, DSDGenContext& dsdGenContext) { + int nParam; + + if ((nParam = fnd_param(szParam, dsdGenContext)) == -1) + return (nParam); + + return ( + (static_cast(dsdGenContext.options[nParam].flags) & OPT_INT) + ? 1 + : 0); +} + +/* + * Routine: IsStrParam(char *szValue, int nParam) + * Purpose: Boolean test for string parameter + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int IsStrParam(const char* szParam, DSDGenContext& dsdGenContext) { + int nParam; + + if ((nParam = fnd_param(szParam, dsdGenContext)) == -1) + return (nParam); + + return ( + (static_cast(dsdGenContext.options[nParam].flags) & OPT_STR) + ? 1 + : 0); +} + +#ifdef TEST + +main() { + init_params(); + set_int("SCALE", "7"); + set_flg("VERBOSE"); + set_str("DISTRIBUTIONS", "'some file name'"); + print_params(); + set_int("s", "8"); + clr_flg("VERBOSE"); + printf("DIST is %s\n", get_str("DISTRIBUTIONS")); + print_params(); + usage(NULL, NULL); +} +#endif /* TEST_PARAMS */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/scaling.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/scaling.cpp new file mode 100644 index 0000000000000..d13e7a5847519 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/scaling.cpp @@ -0,0 +1,785 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "scaling.h" +#include +#include +#include +#include "columns.h" +#include "config.h" +#include "constants.h" +#include "dist.h" +#include "error_msg.h" +#include "genrand.h" +#include "parallel.h" +#include "porting.h" +#include "r_params.h" +#include "scd.h" +#include "tdef_functions.h" +#include "tdefs.h" +#include "tpcds.idx.h" +#include "w_inventory.h" + +void setUpdateScaling(int table, DSDGenContext& dsdGenContext); +int row_skip(int tbl, ds_key_t count, DSDGenContext& dsdGenContext); + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int getScaleSlot(int nTargetGB, DSDGenContext& dsdGenContext) { + int i; + + for (i = 0; nTargetGB > dsdGenContext.arScaleVolume[i]; i++) + ; + + return (i); +} + +/* + * Routine: LogScale(void) + * Purpose: use the command line volume target, in GB, to calculate the global + * rowcount multiplier Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: arRowcounts are set to the appropriate number of rows for the + * target scale factor + * TODO: None + */ +static ds_key_t +LogScale(int nTable, int nTargetGB, DSDGenContext& dsdGenContext) { + int nIndex = 1, nDelta, i; + float fOffset; + ds_key_t hgRowcount = 0; + + i = getScaleSlot(nTargetGB, dsdGenContext); + + nDelta = dist_weight(NULL, "rowcounts", nTable + 1, i + 1, dsdGenContext) - + dist_weight(NULL, "rowcounts", nTable + 1, i, dsdGenContext); + fOffset = + static_cast(nTargetGB - dsdGenContext.arScaleVolume[i - 1]) / + static_cast( + dsdGenContext.arScaleVolume[i] - dsdGenContext.arScaleVolume[i - 1]); + + hgRowcount = static_cast(fOffset * static_cast(nDelta)); + hgRowcount += + dist_weight(NULL, "rowcounts", nTable + 1, nIndex, dsdGenContext); + + return (hgRowcount); +} + +/* + * Routine: StaticScale(void) + * Purpose: use the command line volume target, in GB, to calculate the global + * rowcount multiplier Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: arRowcounts are set to the appropriate number of rows for the + * target scale factor + * TODO: None + */ +static ds_key_t +StaticScale(int nTable, int nTargetGB, DSDGenContext& dsdGenContext) { + return (dist_weight(NULL, "rowcounts", nTable + 1, 1, dsdGenContext)); +} + +/* + * Routine: LinearScale(void) + * Purpose: use the command line volume target, in GB, to calculate the global + *rowcount multiplier Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: scale factors defined in rowcounts distribution define + *1/10/100/1000/... GB with sufficient accuracy Side Effects: arRowcounts are + *set to the appropriate number of rows for the target scale factor + * TODO: None + */ +static ds_key_t +LinearScale(int nTable, int nTargetGB, DSDGenContext& dsdGenContext) { + int i; + ds_key_t hgRowcount = 0; + + for (i = 8; i >= 0; i--) /* work from large scales down)*/ + { + /* + * use the defined rowcounts to build up the target GB volume + */ + while (nTargetGB >= dsdGenContext.arScaleVolume[i]) { + hgRowcount += + dist_weight(NULL, "rowcounts", nTable + 1, i + 1, dsdGenContext); + nTargetGB -= dsdGenContext.arScaleVolume[i]; + } + } + + return (hgRowcount); +} +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t getIDCount(int nTable, DSDGenContext& dsdGenContext) { + ds_key_t kRowcount, kUniqueCount; + tdef* pTdef; + + kRowcount = get_rowcount(nTable, dsdGenContext); + if (nTable >= PSEUDO_TABLE_START) + return (kRowcount); + pTdef = getSimpleTdefsByNumber(nTable, dsdGenContext); + if (pTdef->flags & FL_TYPE_2) { + kUniqueCount = (kRowcount / 6) * 3; + switch (kRowcount % 6) { + case 1: + kUniqueCount += 1; + break; + case 2: + case 3: + kUniqueCount += 2; + break; + case 4: + case 5: + kUniqueCount += 3; + break; + } + return (kUniqueCount); + } else { + return (kRowcount); + } +} + +/* + * Routine: get_rowcount(int table) + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: 20040820 jms Need to address special case scaling in a more general + * fashion + */ +ds_key_t get_rowcount(int table, DSDGenContext& dsdGenContext) { + static double nScale; + int nTable, nMultiplier, i, nBadScale = 0, nRowcountOffset = 0; + tdef* pTdef; + + if (!dsdGenContext.get_rowcount_init) { + nScale = get_dbl("SCALE", dsdGenContext); + if (nScale > 100000) + ReportErrorNoLine(QERR_BAD_SCALE, NULL, 1); + + memset(dsdGenContext.arRowcount, 0, sizeof(long) * MAX_TABLE); + int iScale = nScale < 1 ? 1 : static_cast(nScale); + for (nTable = CALL_CENTER; nTable <= MAX_TABLE; nTable++) { + switch (iScale) { + case 100000: + dsdGenContext.arRowcount[nTable].kBaseRowcount = dist_weight( + NULL, + "rowcounts", + nTable + nRowcountOffset + 1, + 9, + dsdGenContext); + break; + case 30000: + dsdGenContext.arRowcount[nTable].kBaseRowcount = dist_weight( + NULL, + "rowcounts", + nTable + nRowcountOffset + 1, + 8, + dsdGenContext); + break; + case 10000: + dsdGenContext.arRowcount[nTable].kBaseRowcount = dist_weight( + NULL, + "rowcounts", + nTable + nRowcountOffset + 1, + 7, + dsdGenContext); + break; + case 3000: + dsdGenContext.arRowcount[nTable].kBaseRowcount = dist_weight( + NULL, + "rowcounts", + nTable + nRowcountOffset + 1, + 6, + dsdGenContext); + break; + case 1000: + dsdGenContext.arRowcount[nTable].kBaseRowcount = dist_weight( + NULL, + "rowcounts", + nTable + nRowcountOffset + 1, + 5, + dsdGenContext); + break; + case 300: + nBadScale = QERR_BAD_SCALE; + dsdGenContext.arRowcount[nTable].kBaseRowcount = dist_weight( + NULL, + "rowcounts", + nTable + nRowcountOffset + 1, + 4, + dsdGenContext); + break; + case 100: + nBadScale = QERR_BAD_SCALE; + dsdGenContext.arRowcount[nTable].kBaseRowcount = dist_weight( + NULL, + "rowcounts", + nTable + nRowcountOffset + 1, + 3, + dsdGenContext); + break; + case 10: + nBadScale = QERR_BAD_SCALE; + dsdGenContext.arRowcount[nTable].kBaseRowcount = dist_weight( + NULL, + "rowcounts", + nTable + nRowcountOffset + 1, + 2, + dsdGenContext); + break; + case 1: + nBadScale = QERR_QUALIFICATION_SCALE; + dsdGenContext.arRowcount[nTable].kBaseRowcount = dist_weight( + NULL, + "rowcounts", + nTable + nRowcountOffset + 1, + 1, + dsdGenContext); + break; + default: + nBadScale = QERR_BAD_SCALE; + int mem = + dist_member(NULL, "rowcounts", nTable + 1, 3, dsdGenContext); + switch (mem) { + case 2: + dsdGenContext.arRowcount[nTable].kBaseRowcount = + LinearScale(nTable + nRowcountOffset, nScale, dsdGenContext); + break; + case 1: + dsdGenContext.arRowcount[nTable].kBaseRowcount = + StaticScale(nTable + nRowcountOffset, nScale, dsdGenContext); + break; + case 3: + dsdGenContext.arRowcount[nTable].kBaseRowcount = + LogScale(nTable + nRowcountOffset, nScale, dsdGenContext); + break; + } /* switch(FL_SCALE_MASK) */ + break; + } /* switch(nScale) */ + + /* now adjust for the multiplier */ + nMultiplier = 1; + if (nTable < PSEUDO_TABLE_START) { + pTdef = getSimpleTdefsByNumber(nTable, dsdGenContext); + nMultiplier = (pTdef->flags & FL_TYPE_2) ? 2 : 1; + } + for (i = 1; + i <= dist_member(NULL, "rowcounts", nTable + 1, 2, dsdGenContext); + i++) { + nMultiplier *= 10; + } + if (dsdGenContext.arRowcount[nTable].kBaseRowcount >= 0) { + if (nScale < 1) { + int mem = + dist_member(NULL, "rowcounts", nTable + 1, 3, dsdGenContext); + if ((mem > 1)) { + dsdGenContext.arRowcount[nTable].kBaseRowcount = static_cast( + dsdGenContext.arRowcount[nTable].kBaseRowcount * nScale); + } + if (dsdGenContext.arRowcount[nTable].kBaseRowcount == 0) { + dsdGenContext.arRowcount[nTable].kBaseRowcount = 1; + } + } + } + dsdGenContext.arRowcount[nTable].kBaseRowcount *= nMultiplier; + } /* for each table */ + + // if (nBadScale && !is_set("QUIET")) + // ReportErrorNoLine(nBadScale, NULL, 0); + + dsdGenContext.get_rowcount_init = 1; + } + + if (table == INVENTORY) + return (sc_w_inventory(nScale, dsdGenContext)); + if (table == S_INVENTORY) + return ( + getIDCount(ITEM, dsdGenContext) * + get_rowcount(WAREHOUSE, dsdGenContext) * 6); + + return (dsdGenContext.arRowcount[table].kBaseRowcount); +} + +/* + * Routine: setUpdateDates + * Purpose: determine the dates for fact table updates + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void setUpdateDates(DSDGenContext& dsdGenContext) { + assert(0); + int nDay, nUpdate, i; + date_t dtTemp; + + nUpdate = get_int("UPDATE", dsdGenContext); + while (nUpdate--) { + /* pick two adjacent days in the low density zone */ + dsdGenContext.arUpdateDates[0] = + getSkewedJulianDate(calendar_low, 0, dsdGenContext); + jtodt(&dtTemp, dsdGenContext.arUpdateDates[0]); + dist_weight( + &nDay, + "calendar", + day_number(&dtTemp) + 1, + calendar_low, + dsdGenContext); + if (nDay) + dsdGenContext.arUpdateDates[1] = dsdGenContext.arUpdateDates[0] + 1; + else + dsdGenContext.arUpdateDates[1] = dsdGenContext.arUpdateDates[0] - 1; + + /* + * pick the related Thursdays for inventory + * 1. shift first date to the Thursday in the current update week + * 2. move forward/back to get into correct comparability zone + * 3. set next date to next/prior Thursday based on comparability zone + */ + jtodt(&dtTemp, dsdGenContext.arUpdateDates[0] + (4 - set_dow(&dtTemp))); + dist_weight( + &nDay, "calendar", day_number(&dtTemp), calendar_low, dsdGenContext); + dsdGenContext.arInventoryUpdateDates[0] = dtTemp.julian; + if (!nDay) { + jtodt(&dtTemp, dtTemp.julian - 7); + dsdGenContext.arInventoryUpdateDates[0] = dtTemp.julian; + dist_weight( + &nDay, "calendar", day_number(&dtTemp), calendar_low, dsdGenContext); + if (!nDay) + dsdGenContext.arInventoryUpdateDates[0] += 14; + } + + dsdGenContext.arInventoryUpdateDates[1] = + dsdGenContext.arInventoryUpdateDates[0] + 7; + jtodt(&dtTemp, dsdGenContext.arInventoryUpdateDates[1]); + dist_weight( + &nDay, + "calendar", + day_number(&dtTemp) + 1, + calendar_low, + dsdGenContext); + if (!nDay) + dsdGenContext.arInventoryUpdateDates[1] -= 14; + + /* repeat for medium calendar zone */ + dsdGenContext.arUpdateDates[2] = + getSkewedJulianDate(calendar_medium, 0, dsdGenContext); + jtodt(&dtTemp, dsdGenContext.arUpdateDates[2]); + dist_weight( + &nDay, + "calendar", + day_number(&dtTemp) + 1, + calendar_medium, + dsdGenContext); + if (nDay) + dsdGenContext.arUpdateDates[3] = dsdGenContext.arUpdateDates[2] + 1; + else + dsdGenContext.arUpdateDates[3] = dsdGenContext.arUpdateDates[2] - 1; + + jtodt(&dtTemp, dsdGenContext.arUpdateDates[2] + (4 - set_dow(&dtTemp))); + dist_weight( + &nDay, "calendar", day_number(&dtTemp), calendar_medium, dsdGenContext); + dsdGenContext.arInventoryUpdateDates[2] = dtTemp.julian; + if (!nDay) { + jtodt(&dtTemp, dtTemp.julian - 7); + dsdGenContext.arInventoryUpdateDates[2] = dtTemp.julian; + dist_weight( + &nDay, + "calendar", + day_number(&dtTemp), + calendar_medium, + dsdGenContext); + if (!nDay) + dsdGenContext.arInventoryUpdateDates[2] += 14; + } + + dsdGenContext.arInventoryUpdateDates[3] = + dsdGenContext.arInventoryUpdateDates[2] + 7; + jtodt(&dtTemp, dsdGenContext.arInventoryUpdateDates[3]); + dist_weight( + &nDay, "calendar", day_number(&dtTemp), calendar_medium, dsdGenContext); + if (!nDay) + dsdGenContext.arInventoryUpdateDates[3] -= 14; + + /* repeat for high calendar zone */ + dsdGenContext.arUpdateDates[4] = + getSkewedJulianDate(calendar_high, 0, dsdGenContext); + jtodt(&dtTemp, dsdGenContext.arUpdateDates[4]); + dist_weight( + &nDay, + "calendar", + day_number(&dtTemp) + 1, + calendar_high, + dsdGenContext); + if (nDay) + dsdGenContext.arUpdateDates[5] = dsdGenContext.arUpdateDates[4] + 1; + else + dsdGenContext.arUpdateDates[5] = dsdGenContext.arUpdateDates[4] - 1; + + jtodt(&dtTemp, dsdGenContext.arUpdateDates[4] + (4 - set_dow(&dtTemp))); + dist_weight( + &nDay, "calendar", day_number(&dtTemp), calendar_high, dsdGenContext); + dsdGenContext.arInventoryUpdateDates[4] = dtTemp.julian; + if (!nDay) { + jtodt(&dtTemp, dtTemp.julian - 7); + dsdGenContext.arInventoryUpdateDates[4] = dtTemp.julian; + dist_weight( + &nDay, "calendar", day_number(&dtTemp), calendar_high, dsdGenContext); + if (!nDay) + dsdGenContext.arInventoryUpdateDates[4] += 14; + } + + dsdGenContext.arInventoryUpdateDates[5] = + dsdGenContext.arInventoryUpdateDates[4] + 7; + jtodt(&dtTemp, dsdGenContext.arInventoryUpdateDates[5]); + dist_weight( + &nDay, "calendar", day_number(&dtTemp), calendar_high, dsdGenContext); + if (!nDay) + dsdGenContext.arInventoryUpdateDates[5] -= 14; + } + + // /* + // * output the update dates for this update set + // */ + // openDeleteFile(1); + // for (i = 0; i < 6; i += 2) + // print_delete(&arUpdateDates[i]); + // + // /* + // * inventory uses separate dates + // */ + // openDeleteFile(2); + // for (i = 0; i < 6; i += 2) + // print_delete(&arInventoryUpdateDates[i]); + // openDeleteFile(0); + + return; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int getUpdateDate( + int nTable, + ds_key_t kRowcount, + DSDGenContext& dsdGenContext) { + static int nIndex = 0, nLastTable = -1; + + if (nLastTable != nTable) { + nLastTable = nTable; + get_rowcount(nTable, dsdGenContext); + nIndex = 0; + } + + for (nIndex = 0; + kRowcount > dsdGenContext.arRowcount[nTable].kDayRowcount[nIndex]; + nIndex++) + if (nIndex == 5) + break; + + if (nTable == S_INVENTORY) { + return (dsdGenContext.arInventoryUpdateDates[nIndex]); + } else + return (dsdGenContext.arUpdateDates[nIndex]); +} + +/* + * Routine: getUpdateID(int nTable, ds_key_t *pDest) + * Purpose: select the primary key for an update set row + * Algorithm: + * Data Structures: + * + * Params: + * Returns: 1 if the row is new, 0 if it is reusing an existing ID + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: 20040326 jms getUpdateID() this MUST be updated for 64bit -- all usages + * use casts today + * TODO: 20060102 jms this will need to be looked at for parallelism at + * some point + */ +/* +int +getUpdateID(ds_key_t *pDest, int nTable, int nColumn) +{ + int bIsUpdate = 0, + nTemp; + + if (genrand_integer(NULL, DIST_UNIFORM, 0, 99, 0, nColumn, dsdGenContext) < +arRowcount[nTable].nUpdatePercentage) + { + bIsUpdate = 1; + genrand_integer(&nTemp, DIST_UNIFORM, 1, (int, +dsdGenContext)getIDCount(nTable), 0, nColumn); *pDest = (ds_key_t)nTemp; + } + else + { + *pDest = ++arRowcount[nTable].kNextInsertValue; + } + + return(bIsUpdate); +} +*/ + +/* + * Routine: getSkewedJulianDate(int nWeight, int nColumn, DSDGenContext& + * dsdGenContext) Purpose: return a julian date based on the given skew and + * column Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int getSkewedJulianDate( + int nWeight, + int nColumn, + DSDGenContext& dsdGenContext) { + int i; + date_t Date; + + pick_distribution(&i, "calendar", 1, nWeight, nColumn, dsdGenContext); + genrand_integer( + &Date.year, + DIST_UNIFORM, + YEAR_MINIMUM, + YEAR_MAXIMUM, + 0, + nColumn, + dsdGenContext); + dist_member(&Date.day, "calendar", i, 3, dsdGenContext); + dist_member(&Date.month, "calendar", i, 5, dsdGenContext); + return (dttoj(&Date)); +} + +/* + * Routine: dateScaling(int nTable, ds_key_t jDate) + * Purpose: determine the number of rows to build for a given date and fact + * table Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t dateScaling(int nTable, ds_key_t jDate, DSDGenContext& dsdGenContext) { + dist_t* pDist; + const d_idx_t* pDistIndex; + date_t Date; + int nDateWeight = 1, nCalendarTotal, nDayWeight; + ds_key_t kRowCount = -1; + tdef* pTdef = getSimpleTdefsByNumber(nTable, dsdGenContext); + pDistIndex = find_dist("calendar"); + pDist = pDistIndex->dist; + if (!pDist) + ReportError(QERR_NO_MEMORY, "dateScaling()", 1); + + jtodt(&Date, static_cast(jDate)); + + switch (nTable) { + case STORE_SALES: + case CATALOG_SALES: + case WEB_SALES: + kRowCount = get_rowcount(nTable, dsdGenContext); + nDateWeight = calendar_sales; + break; + case S_CATALOG_ORDER: + kRowCount = get_rowcount(CATALOG_SALES, dsdGenContext); + nDateWeight = calendar_sales; + break; + case S_PURCHASE: + kRowCount = get_rowcount(STORE_SALES, dsdGenContext); + nDateWeight = calendar_sales; + break; + case S_WEB_ORDER: + kRowCount = get_rowcount(WEB_SALES, dsdGenContext); + nDateWeight = calendar_sales; + break; + case S_INVENTORY: + case INVENTORY: + nDateWeight = calendar_uniform; + kRowCount = get_rowcount(WAREHOUSE, dsdGenContext) * + getIDCount(ITEM, dsdGenContext); + break; + default: + ReportErrorNoLine(QERR_TABLE_NOP, pTdef->name, 1); + break; + } + + if (nTable != + INVENTORY) /* inventory rowcount is uniform thorughout the year */ + { + if (is_leap(Date.year)) + nDateWeight += 1; + + nCalendarTotal = dist_max(pDist, nDateWeight, dsdGenContext); + nCalendarTotal *= 5; /* assumes date range is 5 years */ + + dist_weight( + &nDayWeight, "calendar", day_number(&Date), nDateWeight, dsdGenContext); + kRowCount *= nDayWeight; + kRowCount += nCalendarTotal / 2; + kRowCount /= nCalendarTotal; + } + + return (kRowCount); +} + +/* + * Routine: getUpdateBase(int nTable) + * Purpose: return the offset to the first order in this update set for a given + * table Algorithm: Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t getUpdateBase(int nTable, DSDGenContext& dsdGenContext) { + return (dsdGenContext.arRowcount[nTable - S_BRAND].kNextInsertValue); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void setUpdateScaling(int nTable, DSDGenContext& dsdGenContext) { + tdef* pTdef; + int i, nBaseTable; + ds_key_t kNewRowcount = 0; + + pTdef = getSimpleTdefsByNumber(nTable, dsdGenContext); + if (!(pTdef->flags & FL_SOURCE_DDL) || !(pTdef->flags & FL_DATE_BASED) || + (pTdef->flags & FL_NOP)) + return; + + switch (nTable) { + case S_PURCHASE: + nBaseTable = STORE_SALES; + break; + case S_CATALOG_ORDER: + nBaseTable = CATALOG_SALES; + break; + case S_WEB_ORDER: + nBaseTable = WEB_SALES; + break; + case S_INVENTORY: + nBaseTable = INVENTORY; + break; + default: { + auto result = + fprintf(stderr, "ERROR: Invalid table in setUpdateScaling\n"); + if (result < 0) + perror("sprintf failed"); + exit(1); + break; + } + } + + dsdGenContext.arRowcount[nTable].kNextInsertValue = + dsdGenContext.arRowcount[nTable].kBaseRowcount; + + for (i = 0; i < 6; i++) { + kNewRowcount += + dateScaling(nBaseTable, dsdGenContext.arUpdateDates[i], dsdGenContext); + dsdGenContext.arRowcount[nTable].kDayRowcount[i] = kNewRowcount; + } + + dsdGenContext.arRowcount[nTable].kBaseRowcount = kNewRowcount; + dsdGenContext.arRowcount[nTable].kNextInsertValue += + kNewRowcount * (get_int("update", dsdGenContext) - 1); + + return; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/scd.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/scd.cpp new file mode 100644 index 0000000000000..5a1e88e8269fc --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/scd.cpp @@ -0,0 +1,382 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "scd.h" +#include +#include "build_support.h" +#include "config.h" +#include "constants.h" +#include "dist.h" +#include "genrand.h" +#include "parallel.h" +#include "params.h" +#include "permute.h" +#include "porting.h" +#include "scaling.h" +#include "tables.h" +#include "tdef_functions.h" +#include "tdefs.h" + +/* an array of the most recent business key for each table */ +char arBKeys[MAX_TABLE][17]; + +/* + * Routine: setSCDKey + * Purpose: handle the versioning and date stamps for slowly changing dimensions + * Algorithm: + * Data Structures: + * + * Params: 1 if there is a new id; 0 otherwise + * Returns: + * Called By: + * Calls: + * Assumptions: Table indexs (surrogate keys) are 1-based. This assures that the + *arBKeys[] entry for each table is initialized. Otherwise, parallel generation + *would be more difficult. Side Effects: + * TODO: None + */ +int setSCDKeys( + int nColumnID, + ds_key_t kIndex, + char* szBKey, + ds_key_t* pkBeginDateKey, + ds_key_t* pkEndDateKey, + DSDGenContext& dsdGenContext) { + int bNewBKey = 0, nModulo; + ds_key_t jMinimumDataDate, jMaximumDataDate, jH1DataDate, jT1DataDate, + jT2DataDate; + date_t dtTemp; + int nTableID; + + strtodt(&dtTemp, DATA_START_DATE); + jMinimumDataDate = dtTemp.julian; + strtodt(&dtTemp, DATA_END_DATE); + jMaximumDataDate = dtTemp.julian; + jH1DataDate = jMinimumDataDate + (jMaximumDataDate - jMinimumDataDate) / 2; + jT2DataDate = (jMaximumDataDate - jMinimumDataDate) / 3; + jT1DataDate = jMinimumDataDate + jT2DataDate; + jT2DataDate += jT1DataDate; + + nTableID = getTableFromColumn(nColumnID, dsdGenContext); + nModulo = (int)(kIndex % 6); + switch (nModulo) { + case 1: /* 1 revision */ + mk_bkey(arBKeys[nTableID], kIndex, nColumnID); + bNewBKey = 1; + *pkBeginDateKey = jMinimumDataDate - nTableID * 6; + *pkEndDateKey = -1; + break; + case 2: /* 1 of 2 revisions */ + mk_bkey(arBKeys[nTableID], kIndex, nColumnID); + bNewBKey = 1; + *pkBeginDateKey = jMinimumDataDate - nTableID * 6; + *pkEndDateKey = jH1DataDate - nTableID * 6; + break; + case 3: /* 2 of 2 revisions */ + mk_bkey(arBKeys[nTableID], kIndex - 1, nColumnID); + *pkBeginDateKey = jH1DataDate - nTableID * 6 + 1; + *pkEndDateKey = -1; + break; + case 4: /* 1 of 3 revisions */ + mk_bkey(arBKeys[nTableID], kIndex, nColumnID); + bNewBKey = 1; + *pkBeginDateKey = jMinimumDataDate - nTableID * 6; + *pkEndDateKey = jT1DataDate - nTableID * 6; + break; + case 5: /* 2 of 3 revisions */ + mk_bkey(arBKeys[nTableID], kIndex - 1, nColumnID); + *pkBeginDateKey = jT1DataDate - nTableID * 6 + 1; + *pkEndDateKey = jT2DataDate - nTableID * 6; + break; + case 0: /* 3 of 3 revisions */ + mk_bkey(arBKeys[nTableID], kIndex - 2, nColumnID); + *pkBeginDateKey = jT2DataDate - nTableID * 6 + 1; + *pkEndDateKey = -1; + break; + } + + /* can't have a revision in the future, per bug 114 */ + if (*pkEndDateKey > jMaximumDataDate) + *pkEndDateKey = -1; + + strcpy(szBKey, arBKeys[nTableID]); + + return (bNewBKey); +} + +/* + * Routine: scd_join(int tbl, int col, ds_key_t jDate) + * Purpose: create joins to slowly changing dimensions + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t +scd_join(int tbl, int col, ds_key_t jDate, DSDGenContext& dsdGenContext) { + ds_key_t res, kRowcount; + static int jMinimumDataDate, jMaximumDataDate, jH1DataDate, jT1DataDate, + jT2DataDate; + date_t dtTemp; + + if (!dsdGenContext.scd_join_init) { + strtodt(&dtTemp, DATA_START_DATE); + jMinimumDataDate = dtTemp.julian; + strtodt(&dtTemp, DATA_END_DATE); + jMaximumDataDate = dtTemp.julian; + jH1DataDate = jMinimumDataDate + (jMaximumDataDate - jMinimumDataDate) / 2; + jT2DataDate = (jMaximumDataDate - jMinimumDataDate) / 3; + jT1DataDate = jMinimumDataDate + jT2DataDate; + jT2DataDate += jT1DataDate; + dsdGenContext.scd_join_init = 1; + } + + kRowcount = getIDCount(tbl, dsdGenContext); + genrand_key( + &res, + DIST_UNIFORM, + 1, + kRowcount, + 0, + col, + dsdGenContext); /* pick the id */ + res = matchSCDSK( + res, + jDate, + tbl, + dsdGenContext); /* map to the date-sensitive surrogate key */ + + /* can't have a revision in the future, per bug 114 */ + if (jDate > jMaximumDataDate) + res = -1; + + return ((res > get_rowcount(tbl, dsdGenContext)) ? -1 : res); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t matchSCDSK( + ds_key_t kUnique, + ds_key_t jDate, + int nTable, + DSDGenContext& dsdGenContext) { + ds_key_t kReturn = -1; + int jMinimumDataDate, jMaximumDataDate; + int jH1DataDate, jT1DataDate, jT2DataDate; + date_t dtTemp; + + strtodt(&dtTemp, DATA_START_DATE); + jMinimumDataDate = dtTemp.julian; + strtodt(&dtTemp, DATA_END_DATE); + jMaximumDataDate = dtTemp.julian; + jH1DataDate = jMinimumDataDate + (jMaximumDataDate - jMinimumDataDate) / 2; + jT2DataDate = (jMaximumDataDate - jMinimumDataDate) / 3; + jT1DataDate = jMinimumDataDate + jT2DataDate; + jT2DataDate += jT1DataDate; + + switch (kUnique % 3) /* number of revisions for the ID */ + { + case 1: /* only one occurrence of this ID */ + kReturn = (kUnique / 3) * 6; + kReturn += 1; + break; + case 2: /* two revisions of this ID */ + kReturn = (kUnique / 3) * 6; + kReturn += 2; + if (jDate > jH1DataDate) + kReturn += 1; + break; + case 0: /* three revisions of this ID */ + kReturn = (kUnique / 3) * 6; + kReturn += -2; + if (jDate > jT1DataDate) + kReturn += 1; + if (jDate > jT2DataDate) + kReturn += 1; + break; + } + + if (kReturn > get_rowcount(nTable, dsdGenContext)) + kReturn = get_rowcount(nTable, dsdGenContext); + + return (kReturn); +} + +/* + * Routine: + * Purpose: map from a unique ID to a random SK + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t getSKFromID(ds_key_t kID, int nColumn, DSDGenContext& dsdGenContext) { + ds_key_t kTemp = -1; + + switch (kID % 3) { + case 1: /* single revision */ + kTemp = kID / 3; + kTemp *= 6; + kTemp += 1; + break; + case 2: /* two revisions */ + kTemp = kID / 3; + kTemp *= 6; + kTemp += + genrand_integer(NULL, DIST_UNIFORM, 2, 3, 0, nColumn, dsdGenContext); + break; + case 0: /* three revisions */ + kTemp = kID / 3; + kTemp -= 1; + kTemp *= 6; + kTemp += + genrand_integer(NULL, DIST_UNIFORM, 4, 6, 0, nColumn, dsdGenContext); + break; + } + + return (kTemp); +} + +/* + * Routine: getFirstSK + * Purpose: map from id to an SK that can be mapped back to an id by printID() + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t getFirstSK(ds_key_t kID) { + ds_key_t kTemp = -1; + + switch (kID % 3) { + case 1: /* single revision */ + kTemp = kID / 3; + kTemp *= 6; + kTemp += 1; + break; + case 2: /* two revisions */ + kTemp = kID / 3; + kTemp *= 6; + kTemp += 2; + break; + case 0: /* three revisions */ + kTemp = kID / 3; + kTemp -= 1; + kTemp *= 6; + kTemp += 4; + break; + } + + return (kTemp); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +void changeSCD( + int nDataType, + void* pNewData, + void* pOldData, + int* nFlags, + int bFirst) { + /** + * if nFlags is odd, then this value will be retained + */ + if ((*nFlags != ((*nFlags / 2) * 2)) && (bFirst == 0)) { + /* + * the method to retain the old value depends on the data type + */ + switch (nDataType) { + case SCD_INT: + *static_cast(pNewData) = *static_cast(pOldData); + break; + case SCD_PTR: + pNewData = pOldData; + break; + case SCD_KEY: + *static_cast(pNewData) = *static_cast(pOldData); + break; + case SCD_CHAR: + strcpy(static_cast(pNewData), static_cast(pOldData)); + break; + case SCD_DEC: + if (pNewData && pOldData) + memcpy(pNewData, pOldData, sizeof(decimal_t)); + break; + } + } else { + /* + * the method to set the old value depends on the data type + */ + switch (nDataType) { + case SCD_INT: + *static_cast(pOldData) = *static_cast(pNewData); + break; + case SCD_PTR: + pOldData = pNewData; + break; + case SCD_KEY: + *static_cast(pOldData) = *static_cast(pNewData); + break; + case SCD_CHAR: + strcpy(static_cast(pOldData), static_cast(pNewData)); + break; + case SCD_DEC: + if (pOldData && pNewData) + memcpy(pOldData, pNewData, sizeof(decimal_t)); + break; + } + } + + *nFlags /= 2; + + return; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/skip_days.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/skip_days.cpp new file mode 100644 index 0000000000000..75a9414ae02d3 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/skip_days.cpp @@ -0,0 +1,49 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "skip_days.h" +#include "constants.h" +#include "date.h" +#include "dist.h" +#include "parallel.h" +#include "scaling.h" + +ds_key_t +skipDays(int nTable, ds_key_t* pRemainder, DSDGenContext& dsdGenContext) { + date_t BaseDate; + ds_key_t jDate; + ds_key_t kRowCount, kFirstRow, kDayCount, index = 1; + + if (!dsdGenContext.skipDays_init) { + *pRemainder = 0; + dsdGenContext.skipDays_init = 1; + } + strtodt(&BaseDate, DATA_START_DATE); + + // set initial conditions + jDate = BaseDate.julian; + *pRemainder = dateScaling(nTable, jDate, dsdGenContext) + index; + + // now check to see if we need to move to the + // the next piece of a parallel build + // move forward one day at a time + split_work(nTable, &kFirstRow, &kRowCount, dsdGenContext); + while (index < kFirstRow) { + kDayCount = dateScaling(nTable, jDate, dsdGenContext); + index += kDayCount; + jDate += 1; + *pRemainder = index; + } + if (index > kFirstRow) { + jDate -= 1; + } + return (jDate); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/sparse.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/sparse.cpp new file mode 100644 index 0000000000000..0175be4723409 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/sparse.cpp @@ -0,0 +1,97 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "sparse.h" +#include "config.h" +#include "error_msg.h" +#include "genrand.h" +#include "porting.h" +#include "scaling.h" +#include "tdefs.h" + +/* + * Routine: initSparseKeys() + * Purpose: set up the set of valid key values for a sparse table. + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: The total population will fit in 32b + * Side Effects: + * TODO: None + */ +int initSparseKeys(int nTable, DSDGenContext& dsdGenContext) { + ds_key_t kRowcount, kOldSeed; + int k; + tdef* pTdef; + + kRowcount = get_rowcount(nTable, dsdGenContext); + pTdef = getTdefsByNumber(nTable, dsdGenContext); + + pTdef->arSparseKeys = static_cast( + malloc(static_cast(kRowcount) * sizeof(ds_key_t))); + MALLOC_CHECK(pTdef->arSparseKeys); + if (pTdef->arSparseKeys == NULL) + ReportError(QERR_NO_MEMORY, "initSparseKeys()", 1); + memset( + pTdef->arSparseKeys, 0, static_cast(kRowcount) * sizeof(ds_key_t)); + + kOldSeed = setSeed(0, nTable, dsdGenContext); + for (k = 0; k < kRowcount; k++) + genrand_key( + &pTdef->arSparseKeys[k], + DIST_UNIFORM, + 1, + pTdef->nParam, + 0, + 0, + dsdGenContext); + setSeed(0, static_cast(kOldSeed), dsdGenContext); + + return (0); +} + +/* + * Routine: randomSparseKey() + * Purpose: randomly select one of the valid key values for a sparse table + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t +randomSparseKey(int nTable, int nColumn, DSDGenContext& dsdGenContext) { + int nKeyIndex; + ds_key_t kRowcount; + tdef* pTdef; + + pTdef = getTdefsByNumber(nTable, dsdGenContext); + kRowcount = get_rowcount(nTable, dsdGenContext); + genrand_integer( + &nKeyIndex, + DIST_UNIFORM, + 1, + static_cast(kRowcount), + 0, + nColumn, + dsdGenContext); + + return (pTdef->arSparseKeys[nKeyIndex]); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/tdef_functions.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/tdef_functions.cpp new file mode 100644 index 0000000000000..5d9026172a37a --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/tdef_functions.cpp @@ -0,0 +1,69 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "tdef_functions.h" +#include "dbgen_version.h" +#include "w_call_center.h" +#include "w_catalog_page.h" +#include "w_catalog_returns.h" +#include "w_catalog_sales.h" +#include "w_customer.h" +#include "w_customer_address.h" +#include "w_customer_demographics.h" +#include "w_datetbl.h" +#include "w_household_demographics.h" +#include "w_income_band.h" +#include "w_inventory.h" +#include "w_item.h" +#include "w_promotion.h" +#include "w_reason.h" +#include "w_ship_mode.h" +#include "w_store.h" +#include "w_store_returns.h" +#include "w_store_sales.h" +#include "w_timetbl.h" +#include "w_warehouse.h" +#include "w_web_page.h" +#include "w_web_returns.h" +#include "w_web_sales.h" +#include "w_web_site.h" + +table_func_t w_tdef_funcs[] = { + {"call_center", mk_w_call_center, {NULL, NULL}, NULL}, + {"catalog_page", mk_w_catalog_page, {NULL, NULL}, NULL}, + {"catalog_returns", NULL, {NULL, NULL}, NULL}, + {"catalog_sales", mk_w_catalog_sales, {NULL, NULL}, NULL}, + {"customer", mk_w_customer, {NULL, NULL}, NULL}, + {"customer_address", mk_w_customer_address, {NULL, NULL}, NULL}, + {"customer_demographics", mk_w_customer_demographics, {NULL, NULL}, NULL}, + {"date", mk_w_date, {NULL, NULL}, NULL}, + {"household_demographics", mk_w_household_demographics, {NULL, NULL}, NULL}, + {"income_band", mk_w_income_band, {NULL, NULL}, NULL}, + {"inventory", mk_w_inventory, {NULL, NULL}, NULL}, + {"item", mk_w_item, {NULL, NULL}, NULL}, + {"promotion", mk_w_promotion, {NULL, NULL}, NULL}, + {"reason", mk_w_reason, {NULL, NULL}, NULL}, + {"ship_mode", mk_w_ship_mode, {NULL, NULL}, NULL}, + {"store", mk_w_store, {NULL, NULL}, NULL}, + {"store_returns", mk_w_store_returns, {NULL, NULL}, NULL}, + {"store_sales", mk_w_store_sales, {NULL, NULL}, NULL}, + {"time", mk_w_time, {NULL, NULL}, NULL}, + {"warehouse", mk_w_warehouse, {NULL, NULL}, NULL}, + {"web_page", mk_w_web_page, {NULL, NULL}, NULL}, + {"web_returns", mk_w_web_returns, {NULL, NULL}, NULL}, + {"web_sales", mk_w_web_sales, {NULL, NULL}, NULL}, + {"web_site", mk_w_web_site, {NULL, NULL}, NULL}, + {"dbgen_version", mk_dbgen_version, {NULL, NULL}, NULL}, + {NULL}}; + +table_func_t* getTdefFunctionsByNumber(int nTable) { + return (&w_tdef_funcs[nTable]); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/tdefs.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/tdefs.cpp new file mode 100644 index 0000000000000..169637c1bc0e8 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/tdefs.cpp @@ -0,0 +1,185 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "tdefs.h" +#include +#include "columns.h" +#include "config.h" +#include "genrand.h" +#include "porting.h" +#include "r_params.h" +#include "scaling.h" +#include "tables.h" +#include "tdef_functions.h" + +/* + * Routine: get_rowcount(int table) + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t GetRowcountByName(char* szName, DSDGenContext& dsdGenContext) { + int nTable = -1; + + nTable = GetTableNumber(szName, dsdGenContext); + if (nTable >= 0) + return (get_rowcount(nTable - 1, dsdGenContext)); + + nTable = distsize(szName, dsdGenContext); + return (nTable); +} + +/* + * Routine: GetTableNumber(char *szName, DSDGenContext& dsdGenContext) + * Purpose: Return size of table, pseudo table or distribution + * Algorithm: Need to use rowcount distribution, since argument could be a + * pseudo table Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int GetTableNumber(char* szName, DSDGenContext& dsdGenContext) { + int i; + + for (i = 1; i <= distsize("rowcounts", dsdGenContext); i++) { + char* szTable = new char[100]; + dist_member(szTable, "rowcounts", i, 1, dsdGenContext); + if (strcasecmp(szTable, szName) == 0) + return (i - 1); + } + + return (-1); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +/* +tdef * +getTdefsByNumber(int nTable) +{ + if (is_set("UPDATE")) + { + if (s_tdefs[nTable].flags & FL_PASSTHRU) + { + switch(nTable + S_BRAND) + { + case S_CATALOG_PAGE: nTable = CATALOG_PAGE; break; + case S_CUSTOMER_ADDRESS: nTable = CUSTOMER_ADDRESS; break; + case S_PROMOTION: nTable = PROMOTION; break; + } + return(&w_tdefs[nTable]); + } + else + return(&s_tdefs[nTable]); + } + else + return(&w_tdefs[nTable]); +} +*/ +tdef* getSimpleTdefsByNumber(int nTable, DSDGenContext& dsdGenContext) { + if (nTable >= S_BRAND) + return (&dsdGenContext.s_tdefs[nTable - S_BRAND]); + return (&dsdGenContext.w_tdefs[nTable]); +} + +tdef* getTdefsByNumber(int nTable, DSDGenContext& dsdGenContext) { + if (is_set("UPDATE", dsdGenContext) && is_set("VALIDATE", dsdGenContext)) { + if (static_cast(dsdGenContext.s_tdefs[nTable].flags) & + FL_PASSTHRU) { + switch (nTable + S_BRAND) { + case S_CATALOG_PAGE: + nTable = CATALOG_PAGE; + break; + case S_CUSTOMER_ADDRESS: + nTable = CUSTOMER_ADDRESS; + break; + case S_PROMOTION: + nTable = PROMOTION; + break; + } + return (&dsdGenContext.w_tdefs[nTable]); + } else + return (&dsdGenContext.s_tdefs[nTable]); + } + + return (getSimpleTdefsByNumber(nTable, dsdGenContext)); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +const char* getTableNameByID(int i, DSDGenContext& dsdGenContext) { + tdef* pT = getSimpleTdefsByNumber(i, dsdGenContext); + + return (pT->name); +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int getTableFromColumn(int nColumn, DSDGenContext& dsdGenContext) { + int i; + tdef* pT; + + for (i = 0; i <= MAX_TABLE; i++) { + pT = getSimpleTdefsByNumber(i, dsdGenContext); + if ((nColumn >= pT->nFirstColumn) && (nColumn <= pT->nLastColumn)) + return (i); + } + return (-1); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/text.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/text.cpp new file mode 100644 index 0000000000000..0305f83b25c35 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/text.cpp @@ -0,0 +1,185 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include +#include +#include +#include "config.h" +#include "date.h" +#include "decimal.h" +#include "dist.h" +#include "genrand.h" +#include "porting.h" + +/* + * Routine: mk_sentence() + * Purpose: create a sample sentence + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +#define SPACE_INCREMENT 100 + +char* mk_sentence(int stream, DSDGenContext& dsdGenContext) { + char* verbiage = nullptr; + int used_space = 0; /* current length of the sentence being built */ + int allocated_space = 0; + int word_len = 0; + char *syntax = nullptr, *cp = nullptr, *word = nullptr, temp[2]; + + temp[1] = '\0'; + pick_distribution(&syntax, "sentences", 1, 1, stream, dsdGenContext); + + for (cp = syntax; *cp; cp++) { + switch (*cp) { + case 'N': /* pick a noun */ + pick_distribution(&word, "nouns", 1, 1, stream, dsdGenContext); + break; + case 'V': /* pick a verb */ + pick_distribution(&word, "verbs", 1, 1, stream, dsdGenContext); + break; + case 'J': /* pick a adjective */ + pick_distribution(&word, "adjectives", 1, 1, stream, dsdGenContext); + break; + case 'D': /* pick a adverb */ + pick_distribution(&word, "adverbs", 1, 1, stream, dsdGenContext); + break; + case 'X': /* pick a auxiliary verb */ + pick_distribution(&word, "auxiliaries", 1, 1, stream, dsdGenContext); + break; + case 'P': /* pick a preposition */ + pick_distribution(&word, "prepositions", 1, 1, stream, dsdGenContext); + break; + case 'A': /* pick an article */ + pick_distribution(&word, "articles", 1, 1, stream, dsdGenContext); + break; + case 'T': /* pick an terminator */ + pick_distribution(&word, "terminators", 1, 1, stream, dsdGenContext); + break; + default: + temp[0] = *cp; + break; + } + + if (word == nullptr) + word_len = 1; + else + word_len = strlen(word); + + if (used_space + word_len >= allocated_space) { + verbiage = static_cast( + realloc(verbiage, allocated_space + SPACE_INCREMENT)); + MALLOC_CHECK(verbiage); + allocated_space += SPACE_INCREMENT; + } + + if (word == nullptr) + strcpy(&verbiage[used_space], temp); + else + strcpy(&verbiage[used_space], word); + used_space += word_len; + word = nullptr; + } + + return (verbiage); +} + +/* + * Routine: gen_text() + * Purpose: entry point for this module. Generate a truncated sentence in a + * given length range + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +char* gen_text( + char* dest, + int min, + int max, + int stream, + DSDGenContext& dsdGenContext) { + int target_len = 0, generated_length = 0, capitalize = 1; + char* s = nullptr; + + genrand_integer( + &target_len, DIST_UNIFORM, min, max, 0, stream, dsdGenContext); + if (dest) + *dest = '\0'; + else { + dest = static_cast(malloc((max + 1) * sizeof(char))); + MALLOC_CHECK(dest); + } + + while (target_len > 0) { + s = mk_sentence(stream, dsdGenContext); + if (capitalize) + *s = toupper(*s); + generated_length = strlen(s); + capitalize = (s[generated_length - 1] == '.'); + if (target_len <= generated_length) + s[target_len] = '\0'; + strcat(dest, s); + target_len -= generated_length; + if (target_len > 0) { + strcat(dest, " "); + target_len -= 1; + } + } + + return (dest); +} + +#ifdef TEST +#define DECLARER +#include "r_driver.h" +#include "r_params.h" + +typedef struct { + char* name; +} tdef; +/* tdef tdefs[] = {NULL}; */ + +option_t options[] = { + + {"DISTRIBUTIONS", OPT_STR, 0, NULL, NULL, "tester_dist.idx"}, + NULL}; + +char* params[2]; + +main() { + char test_dest[201]; + int i; + + init_params(); + + for (i = 0; i < 100; i++) { + gen_text(test_dest, 100, 200, 1); + printf("%s\n", test_dest); + test_dest[0] = '\0'; + } + + return (0); +} +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_call_center.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_call_center.cpp new file mode 100644 index 0000000000000..564a1dae9614f --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_call_center.cpp @@ -0,0 +1,347 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_call_center.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "date.h" +#include "decimal.h" +#include "dist.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "parallel.h" +#include "porting.h" +#include "r_params.h" +#include "scaling.h" +#include "scd.h" +#include "tables.h" +#include "tdefs.h" + +#include +#include +#include + +static struct CALL_CENTER_TBL g_call_center_OldValues; + +/* + * Routine: mk_w_call_center() + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20020830 jms Need to populate open and close dates + */ + +int mk_w_call_center( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + int32_t jDateStart, nDaysPerRevision; + int32_t nSuffix, bFirstRecord = 0, nFieldChangeFlags, jDateEnd, nDateRange; + char *cp = nullptr, *sName1 = nullptr, *sName2 = nullptr; + decimal_t dMinTaxPercentage, dMaxTaxPercentage; + tdef* pTdef = getSimpleTdefsByNumber(CALL_CENTER, dsdGenContext); + + /* begin locals declarations */ + date_t dTemp; + double nScale; + struct CALL_CENTER_TBL *r, *rOldValues = &g_call_center_OldValues; + + r = &dsdGenContext.g_w_call_center; + + strtodt(&dTemp, DATA_START_DATE); + jDateStart = dttoj(&dTemp) - WEB_SITE; + strtodt(&dTemp, DATA_END_DATE); + jDateEnd = dttoj(&dTemp); + nDateRange = jDateEnd - jDateStart + 1; + nDaysPerRevision = nDateRange / pTdef->nParam + 1; + nScale = get_dbl("SCALE", dsdGenContext); + + r->cc_division_id = -1; + r->cc_closed_date_id = -1; + strcpy(r->cc_division_name, "No Name"); + + strtodec(&dMinTaxPercentage, MIN_CC_TAX_PERCENTAGE); + strtodec(&dMaxTaxPercentage, MAX_CC_TAX_PERCENTAGE); + + nullSet(&pTdef->kNullBitMap, CC_NULLS, dsdGenContext); + r->cc_call_center_sk = index; + + /* if we have generated the required history for this business key and + * generate a new one then reset associate fields (e.g., rec_start_date + * minimums) + */ + if (setSCDKeys( + CC_CALL_CENTER_ID, + index, + r->cc_call_center_id, + &r->cc_rec_start_date_id, + &r->cc_rec_end_date_id, + dsdGenContext)) { + r->cc_open_date_id = + jDateStart - + genrand_integer( + NULL, DIST_UNIFORM, -365, 0, 0, CC_OPEN_DATE_ID, dsdGenContext); + + /* + * some fields are not changed, even when a new version of the row is + * written + */ + nSuffix = static_cast(index / distsize("call_centers", dsdGenContext)); + dist_member( + &cp, + "call_centers", + static_cast((index % distsize("call_centers", dsdGenContext)) + 1), + 1, + dsdGenContext); + if (nSuffix > 0) { + snprintf(r->cc_name, RS_CC_NAME + 1, "%s_%d", cp, nSuffix); + } else + strcpy(r->cc_name, cp); + + mk_address(&r->cc_address, CC_ADDRESS, dsdGenContext); + bFirstRecord = 1; + } + + /* + * this is where we select the random number that controls if a field + * changes from one record to the next. + */ + nFieldChangeFlags = next_random(CC_SCD, dsdGenContext); + + /* the rest of the record in a history-keeping dimension can either be a new + * data value or not; use a random number and its bit pattern to determine + * which fields to replace and which to retain + */ + pick_distribution( + &r->cc_class, "call_center_class", 1, 1, CC_CLASS, dsdGenContext); + changeSCD( + SCD_PTR, + &r->cc_class, + &rOldValues->cc_class, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->cc_employees, + DIST_UNIFORM, + 1, + nScale >= 1 ? static_cast(CC_EMPLOYEE_MAX * nScale * nScale) + : static_cast(CC_EMPLOYEE_MAX), + 0, + CC_EMPLOYEES, + dsdGenContext); + changeSCD( + SCD_INT, + &r->cc_employees, + &rOldValues->cc_employees, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->cc_sq_ft, DIST_UNIFORM, 100, 700, 0, CC_SQ_FT, dsdGenContext); + r->cc_sq_ft *= r->cc_employees; + changeSCD( + SCD_INT, + &r->cc_sq_ft, + &rOldValues->cc_sq_ft, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution( + &r->cc_hours, "call_center_hours", 1, 1, CC_HOURS, dsdGenContext); + changeSCD( + SCD_PTR, + &r->cc_hours, + &rOldValues->cc_hours, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution(&sName1, "first_names", 1, 1, CC_MANAGER, dsdGenContext); + pick_distribution(&sName2, "last_names", 1, 1, CC_MANAGER, dsdGenContext); + snprintf(&r->cc_manager[0], RS_CC_MANAGER + 1, "%s %s", sName1, sName2); + changeSCD( + SCD_CHAR, + &r->cc_manager, + &rOldValues->cc_manager, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->cc_market_id, DIST_UNIFORM, 1, 6, 0, CC_MARKET_ID, dsdGenContext); + changeSCD( + SCD_INT, + &r->cc_market_id, + &rOldValues->cc_market_id, + &nFieldChangeFlags, + bFirstRecord); + + gen_text( + r->cc_market_class, + 20, + RS_CC_MARKET_CLASS, + CC_MARKET_CLASS, + dsdGenContext); + changeSCD( + SCD_CHAR, + &r->cc_market_class, + &rOldValues->cc_market_class, + &nFieldChangeFlags, + bFirstRecord); + + gen_text( + r->cc_market_desc, 20, RS_CC_MARKET_DESC, CC_MARKET_DESC, dsdGenContext); + changeSCD( + SCD_CHAR, + &r->cc_market_desc, + &rOldValues->cc_market_desc, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution( + &sName1, "first_names", 1, 1, CC_MARKET_MANAGER, dsdGenContext); + pick_distribution( + &sName2, "last_names", 1, 1, CC_MARKET_MANAGER, dsdGenContext); + snprintf( + &r->cc_market_manager[0], + RS_CC_MARKET_MANAGER + 1, + "%s %s", + sName1, + sName2); + changeSCD( + SCD_CHAR, + &r->cc_market_manager, + &rOldValues->cc_market_manager, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->cc_company, DIST_UNIFORM, 1, 6, 0, CC_COMPANY, dsdGenContext); + changeSCD( + SCD_INT, + &r->cc_company, + &rOldValues->cc_company, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->cc_division_id, DIST_UNIFORM, 1, 6, 0, CC_COMPANY, dsdGenContext); + changeSCD( + SCD_INT, + &r->cc_division_id, + &rOldValues->cc_division_id, + &nFieldChangeFlags, + bFirstRecord); + + mk_word( + r->cc_division_name, + "syllables", + r->cc_division_id, + RS_CC_DIVISION_NAME, + CC_DIVISION_NAME, + dsdGenContext); + changeSCD( + SCD_CHAR, + &r->cc_division_name, + &rOldValues->cc_division_name, + &nFieldChangeFlags, + bFirstRecord); + + mk_companyname( + r->cc_company_name, CC_COMPANY_NAME, r->cc_company, dsdGenContext); + changeSCD( + SCD_CHAR, + &r->cc_company_name, + &rOldValues->cc_company_name, + &nFieldChangeFlags, + bFirstRecord); + + genrand_decimal( + &r->cc_tax_percentage, + DIST_UNIFORM, + &dMinTaxPercentage, + &dMaxTaxPercentage, + NULL, + CC_TAX_PERCENTAGE, + dsdGenContext); + changeSCD( + SCD_DEC, + &r->cc_tax_percentage, + &rOldValues->cc_tax_percentage, + &nFieldChangeFlags, + bFirstRecord); + + // append the newly created row + char szTemp[128]; + + void* info = append_info_get(info_arr, CALL_CENTER); + + append_row_start(info); + append_key(CC_CALL_CENTER_SK, info, r->cc_call_center_sk); + append_varchar(CC_CALL_CENTER_ID, info, r->cc_call_center_id); + append_date(CC_REC_START_DATE_ID, info, r->cc_rec_start_date_id); + append_date(CC_REC_END_DATE_ID, info, r->cc_rec_end_date_id); + append_integer(CC_CLOSED_DATE_ID, info, r->cc_closed_date_id); + append_integer(CC_OPEN_DATE_ID, info, r->cc_open_date_id); + append_varchar(CC_NAME, info, r->cc_name); + append_varchar(CC_CLASS, info, &r->cc_class[0]); + append_integer(CC_EMPLOYEES, info, r->cc_employees); + append_integer(CC_SQ_FT, info, r->cc_sq_ft); + append_varchar(CC_HOURS, info, r->cc_hours); + append_varchar(CC_MANAGER, info, &r->cc_manager[0]); + append_integer(CC_MARKET_ID, info, r->cc_market_id); + append_varchar(CC_MARKET_CLASS, info, &r->cc_market_class[0]); + append_varchar(CC_MARKET_DESC, info, &r->cc_market_desc[0]); + append_varchar(CC_MARKET_MANAGER, info, &r->cc_market_manager[0]); + append_integer(CC_DIVISION, info, r->cc_division_id); + append_varchar(CC_DIVISION_NAME, info, &r->cc_division_name[0]); + append_integer(CC_COMPANY, info, r->cc_company); + append_varchar(CC_COMPANY_NAME, info, &r->cc_company_name[0]); + append_varchar(CC_ADDRESS, info, std::to_string(r->cc_address.street_num)); + + if (r->cc_address.street_name2) { + snprintf( + szTemp, + sizeof(szTemp), + "%s %s", + r->cc_address.street_name1, + r->cc_address.street_name2); + append_varchar(CC_ADDRESS, info, szTemp); + } else { + append_varchar(CC_ADDRESS, info, r->cc_address.street_name1); + } + + append_varchar(CC_ADDRESS, info, r->cc_address.street_type); + append_varchar(CC_ADDRESS, info, &r->cc_address.suite_num[0]); + append_varchar(CC_ADDRESS, info, r->cc_address.city); + append_varchar(CC_ADDRESS, info, r->cc_address.county); + append_varchar(CC_ADDRESS, info, r->cc_address.state); + snprintf(szTemp, sizeof(szTemp), "%05d", r->cc_address.zip); + append_varchar(CC_ADDRESS, info, szTemp); + append_varchar(CC_ADDRESS, info, &r->cc_address.country[0]); + append_integer_decimal(CC_GMT_OFFSET, info, r->cc_address.gmt_offset); + append_decimal(CC_TAX_PERCENTAGE, info, &r->cc_tax_percentage); + + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_catalog_page.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_catalog_page.cpp new file mode 100644 index 0000000000000..2063e8b453d90 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_catalog_page.cpp @@ -0,0 +1,124 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_catalog_page.h" + +#include "append_info.h" +#include "build_support.h" +#include "config.h" +#include "constants.h" +#include "date.h" +#include "decimal.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "porting.h" +#include "scaling.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * Routine: mk_catalog_page() + * Purpose: populate the catalog_page table + * Algorithm: + * catalogs are issued either monthly, quarterly or bi-annually (cp_type) + * there is 1 of each type circulating at all times + * Data tdefsures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20020903 jms cp_department needs to be randomized + * 20020903 jms cp_description needs to be randomized + */ +int mk_w_catalog_page( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + date_t* dStartDate; + int nCatalogPageMax; + int nDuration, nOffset, nType; + struct CATALOG_PAGE_TBL* r; + int nCatalogInterval; + tdef* pTdef = getSimpleTdefsByNumber(CATALOG_PAGE, dsdGenContext); + + r = &dsdGenContext.g_w_catalog_page; + + nCatalogPageMax = + (static_cast( + get_rowcount(CATALOG_PAGE, dsdGenContext) / CP_CATALOGS_PER_YEAR)) / + (YEAR_MAXIMUM - YEAR_MINIMUM + 2); + dStartDate = strtodate(DATA_START_DATE); + strcpy(r->cp_department, "DEPARTMENT"); + + nullSet(&pTdef->kNullBitMap, CP_NULLS, dsdGenContext); + r->cp_catalog_page_sk = index; + mk_bkey(&r->cp_catalog_page_id[0], index, CP_CATALOG_PAGE_ID); + r->cp_catalog_number = static_cast((index - 1) / nCatalogPageMax + 1); + r->cp_catalog_page_number = + static_cast((index - 1) % nCatalogPageMax + 1); + switch (nCatalogInterval = + ((r->cp_catalog_number - 1) % CP_CATALOGS_PER_YEAR)) { + case 0: /* bi-annual */ + case 1: + nType = 1; + nDuration = 182; + nOffset = nCatalogInterval * nDuration; + break; + case 2: + case 3: /* Q2 */ + case 4: /* Q3 */ + case 5: /* Q4 */ + nDuration = 91; + nOffset = (nCatalogInterval - 2) * nDuration; + nType = 2; + break; + default: + nDuration = 30; + nOffset = (nCatalogInterval - 6) * nDuration; + nType = 3; /* monthly */ + } + r->cp_start_date_id = dStartDate->julian + nOffset; + r->cp_start_date_id += + ((r->cp_catalog_number - 1) / CP_CATALOGS_PER_YEAR) * 365; + r->cp_end_date_id = r->cp_start_date_id + nDuration - 1; + dist_member(&r->cp_type, "catalog_page_type", nType, 1, dsdGenContext); + gen_text( + &r->cp_description[0], + RS_CP_DESCRIPTION / 2, + RS_CP_DESCRIPTION - 1, + CP_DESCRIPTION, + dsdGenContext); + + void* info = append_info_get(info_arr, CATALOG_PAGE); + + append_row_start(info); + + append_key(CP_CATALOG_PAGE_SK, info, r->cp_catalog_page_sk); + append_varchar(CP_CATALOG_PAGE_ID, info, r->cp_catalog_page_id); + append_integer(CP_START_DATE_ID, info, r->cp_start_date_id); + append_integer(CP_END_DATE_ID, info, r->cp_end_date_id); + append_varchar(CP_DEPARTMENT, info, &r->cp_department[0]); + append_integer(CP_CATALOG_NUMBER, info, r->cp_catalog_number); + append_integer(CP_CATALOG_PAGE_NUMBER, info, r->cp_catalog_page_number); + append_varchar(CP_DESCRIPTION, info, &r->cp_description[0]); + append_varchar(CP_TYPE, info, r->cp_type); + + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_catalog_returns.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_catalog_returns.cpp new file mode 100644 index 0000000000000..ac785dc89e92d --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_catalog_returns.cpp @@ -0,0 +1,144 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_catalog_returns.h" +#include +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "constants.h" +#include "genrand.h" +#include "nulls.h" +#include "parallel.h" +#include "porting.h" +#include "tables.h" +#include "tdefs.h" +#include "w_catalog_sales.h" + +/* + * Routine: mk_catalog_returns() + * Purpose: populate a return fact *sync'd with a sales fact* + * Algorithm: Since the returns need to be in line with a prior sale, they need + * to use the output of the mk_catalog_sales() routine, and then add + *return-related information Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20020902 jms Need to link call center to date/time of return + * 20031023 jms removed ability for stand alone generation + */ +int mk_w_catalog_returns( + void* row, + ds_key_t index, + DSDGenContext& dsdGenContext) { + int res = 0; + + decimal_t dHundred; + int nTemp; + struct W_CATALOG_RETURNS_TBL* r; + struct W_CATALOG_SALES_TBL* sale = &dsdGenContext.g_w_catalog_sales; + static int bStandAlone = 0; + tdef* pTdef = getSimpleTdefsByNumber(CATALOG_RETURNS, dsdGenContext); + + if (row == NULL) + r = &dsdGenContext.g_w_catalog_returns; + else + r = static_cast(row); + strtodec(&dHundred, "100.00"); + + /* if we were not called from the parent table's mk_xxx routine, then + * move to a parent row that needs to be returned, and generate it + */ + nullSet(&pTdef->kNullBitMap, CR_NULLS, dsdGenContext); + if (bStandAlone) { + genrand_integer( + &nTemp, DIST_UNIFORM, 0, 99, 0, CR_IS_RETURNED, dsdGenContext); + if (nTemp >= CR_RETURN_PCT) { + row_skip(CATALOG_SALES, 1, dsdGenContext); + return (1); + } + mk_w_catalog_sales(&dsdGenContext.g_w_catalog_sales, index, dsdGenContext); + } + + /* + * Some of the information in the return is taken from the original sale + * which has been regenerated + */ + r->cr_item_sk = sale->cs_sold_item_sk; + r->cr_catalog_page_sk = sale->cs_catalog_page_sk; + r->cr_order_number = sale->cs_order_number; + memcpy(&r->cr_pricing, &sale->cs_pricing, sizeof(ds_pricing_t)); + r->cr_refunded_customer_sk = sale->cs_bill_customer_sk; + r->cr_refunded_cdemo_sk = sale->cs_bill_cdemo_sk; + r->cr_refunded_hdemo_sk = sale->cs_bill_hdemo_sk; + r->cr_refunded_addr_sk = sale->cs_bill_addr_sk; + r->cr_call_center_sk = sale->cs_call_center_sk; + + /* + * some of the fields are conditionally taken from the sale + */ + r->cr_returning_customer_sk = + mk_join(CR_RETURNING_CUSTOMER_SK, CUSTOMER, 2, dsdGenContext); + r->cr_returning_cdemo_sk = + mk_join(CR_RETURNING_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 2, dsdGenContext); + r->cr_returning_hdemo_sk = + mk_join(CR_RETURNING_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 2, dsdGenContext); + r->cr_returning_addr_sk = + mk_join(CR_RETURNING_ADDR_SK, CUSTOMER_ADDRESS, 2, dsdGenContext); + if (genrand_integer( + NULL, + DIST_UNIFORM, + 0, + 99, + 0, + CR_RETURNING_CUSTOMER_SK, + dsdGenContext) < CS_GIFT_PCT) { + r->cr_returning_customer_sk = sale->cs_ship_customer_sk; + r->cr_returning_cdemo_sk = sale->cs_ship_cdemo_sk; + /* cr_returning_hdemo_sk removed, since it doesn't exist on the sales + * record */ + r->cr_returning_addr_sk = sale->cs_ship_addr_sk; + } + + /** + * the rest of the columns are generated for this specific return + */ + /* the items cannot be returned until they are shipped; offset is handled in + * mk_join, based on sales date */ + r->cr_returned_date_sk = + mk_join(CR_RETURNED_DATE_SK, DATET, sale->cs_ship_date_sk, dsdGenContext); + + /* the call center determines the time of the return */ + r->cr_returned_time_sk = mk_join(CR_RETURNED_TIME_SK, TIME, 1, dsdGenContext); + + r->cr_ship_mode_sk = mk_join(CR_SHIP_MODE_SK, SHIP_MODE, 1, dsdGenContext); + r->cr_warehouse_sk = mk_join(CR_WAREHOUSE_SK, WAREHOUSE, 1, dsdGenContext); + r->cr_reason_sk = mk_join(CR_REASON_SK, REASON, 1, dsdGenContext); + if (sale->cs_pricing.quantity != -1) + genrand_integer( + &r->cr_pricing.quantity, + DIST_UNIFORM, + 1, + sale->cs_pricing.quantity, + 0, + CR_PRICING, + dsdGenContext); + else + r->cr_pricing.quantity = -1; + set_pricing(CR_PRICING, &r->cr_pricing, dsdGenContext); + + return (res); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_catalog_sales.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_catalog_sales.cpp new file mode 100644 index 0000000000000..2a0bbd75f0965 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_catalog_sales.cpp @@ -0,0 +1,376 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_catalog_sales.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "constants.h" +#include "date.h" +#include "decimal.h" +#include "genrand.h" +#include "nulls.h" +#include "parallel.h" +#include "params.h" +#include "permute.h" +#include "porting.h" +#include "scaling.h" +#include "scd.h" +#include "tables.h" +#include "tdefs.h" +#include "w_catalog_returns.h" + +#include + +ds_key_t +skipDays(int nTable, ds_key_t* pRemainder, DSDGenContext& dsdGenContext); + +/* + * the validation process requires generating a single lineitem + * so the main mk_xxx routine has been split into a master record portion + * and a detail/lineitem portion. + */ +W_CATALOG_SALES_TBL* mk_catalog_sales_master( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + decimal_t dZero, dHundred, dOne, dOneHalf; + int nGiftPct; + struct W_CATALOG_SALES_TBL* r; + r = &dsdGenContext.g_w_catalog_sales; + + if (!dsdGenContext.mk_master_catalog_sales_init) { + dsdGenContext.jDate = + skipDays(CATALOG_SALES, &dsdGenContext.kNewDateIndex, dsdGenContext); + dsdGenContext.pCatalogSalesItemPermutation = makePermutation( + NULL, + (dsdGenContext.nCatalogSalesItemCount = + static_cast(getIDCount(ITEM, dsdGenContext))), + CS_PERMUTE, + dsdGenContext); + + dsdGenContext.mk_master_catalog_sales_init = 1; + } + + strtodec(&dZero, "0.00"); + strtodec(&dHundred, "100.00"); + strtodec(&dOne, "1.00"); + strtodec(&dOneHalf, "0.50"); + + while (index > dsdGenContext.kNewDateIndex) /* need to move to a new date */ + { + dsdGenContext.jDate += 1; + dsdGenContext.kNewDateIndex += + dateScaling(CATALOG_SALES, dsdGenContext.jDate, dsdGenContext); + } + + /*** + * some attributes remain the same for each lineitem in an order; others are + * different for each lineitem. + * + * Parallel generation causes another problem, since the values that get + * seeded may come from a prior row. If we are seeding at the start of a + * parallel chunk, hunt backwards in the RNG stream to find the most recent + * values that were used to set the values of the orderline-invariant + * columns + */ + + r->cs_sold_date_sk = dsdGenContext.jDate; + r->cs_sold_time_sk = + mk_join(CS_SOLD_TIME_SK, TIME, r->cs_call_center_sk, dsdGenContext); + r->cs_call_center_sk = (r->cs_sold_date_sk == -1) + ? -1 + : mk_join( + CS_CALL_CENTER_SK, CALL_CENTER, r->cs_sold_date_sk, dsdGenContext); + + r->cs_bill_customer_sk = + mk_join(CS_BILL_CUSTOMER_SK, CUSTOMER, 1, dsdGenContext); + r->cs_bill_cdemo_sk = + mk_join(CS_BILL_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1, dsdGenContext); + r->cs_bill_hdemo_sk = + mk_join(CS_BILL_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1, dsdGenContext); + r->cs_bill_addr_sk = + mk_join(CS_BILL_ADDR_SK, CUSTOMER_ADDRESS, 1, dsdGenContext); + + /* most orders are for the ordering customers, some are not */ + genrand_integer( + &nGiftPct, DIST_UNIFORM, 0, 99, 0, CS_SHIP_CUSTOMER_SK, dsdGenContext); + if (nGiftPct <= CS_GIFT_PCT) { + r->cs_ship_customer_sk = + mk_join(CS_SHIP_CUSTOMER_SK, CUSTOMER, 2, dsdGenContext); + r->cs_ship_cdemo_sk = + mk_join(CS_SHIP_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 2, dsdGenContext); + r->cs_ship_hdemo_sk = + mk_join(CS_SHIP_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 2, dsdGenContext); + r->cs_ship_addr_sk = + mk_join(CS_SHIP_ADDR_SK, CUSTOMER_ADDRESS, 2, dsdGenContext); + } else { + r->cs_ship_customer_sk = r->cs_bill_customer_sk; + r->cs_ship_cdemo_sk = r->cs_bill_cdemo_sk; + r->cs_ship_hdemo_sk = r->cs_bill_hdemo_sk; + r->cs_ship_addr_sk = r->cs_bill_addr_sk; + } + + r->cs_order_number = index; + genrand_integer( + &dsdGenContext.nTicketItemBase, + DIST_UNIFORM, + 1, + dsdGenContext.nCatalogSalesItemCount, + 0, + CS_SOLD_ITEM_SK, + dsdGenContext); + + return r; +} + +static void mk_detail( + void* info_arr, + int bPrint, + struct W_CATALOG_SALES_TBL* r, + DSDGenContext& dsdGenContext) { + int nShipLag, nTemp; + ds_key_t kItem; + tdef* pTdef = getSimpleTdefsByNumber(CATALOG_SALES, dsdGenContext); + + r = &dsdGenContext.g_w_catalog_sales; + + nullSet(&pTdef->kNullBitMap, CS_NULLS, dsdGenContext); + + /* orders are shipped some number of days after they are ordered */ + genrand_integer( + &nShipLag, + DIST_UNIFORM, + CS_MIN_SHIP_DELAY, + CS_MAX_SHIP_DELAY, + 0, + CS_SHIP_DATE_SK, + dsdGenContext); + r->cs_ship_date_sk = + (r->cs_sold_date_sk == -1) ? -1 : r->cs_sold_date_sk + nShipLag; + + /* + * items need to be unique within an order + * use a sequence within the permutation + * NB: Permutations are 1-based + */ + if (++dsdGenContext.nTicketItemBase > dsdGenContext.nCatalogSalesItemCount) + dsdGenContext.nTicketItemBase = 1; + kItem = getPermutationEntry( + dsdGenContext.pCatalogSalesItemPermutation, + dsdGenContext.nTicketItemBase); + r->cs_sold_item_sk = + matchSCDSK(kItem, r->cs_sold_date_sk, ITEM, dsdGenContext); + + /* catalog page needs to be from a catlog active at the time of the sale */ + r->cs_catalog_page_sk = (r->cs_sold_date_sk == -1) ? -1 + : mk_join( + CS_CATALOG_PAGE_SK, + CATALOG_PAGE, + r->cs_sold_date_sk, + dsdGenContext); + + r->cs_ship_mode_sk = mk_join(CS_SHIP_MODE_SK, SHIP_MODE, 1, dsdGenContext); + r->cs_warehouse_sk = mk_join(CS_WAREHOUSE_SK, WAREHOUSE, 1, dsdGenContext); + r->cs_promo_sk = mk_join(CS_PROMO_SK, PROMOTION, 1, dsdGenContext); + set_pricing(CS_PRICING, &r->cs_pricing, dsdGenContext); + + /** + * having gone to the trouble to make the sale, now let's see if it gets + * returned + */ + genrand_integer( + &nTemp, DIST_UNIFORM, 0, 99, 0, CR_IS_RETURNED, dsdGenContext); + if (nTemp < CR_RETURN_PCT) { + struct W_CATALOG_RETURNS_TBL w_catalog_returns; + struct W_CATALOG_RETURNS_TBL* rr = &dsdGenContext.g_w_catalog_returns; + mk_w_catalog_returns(rr, 1, dsdGenContext); + + void* info = append_info_get(info_arr, CATALOG_RETURNS); + append_row_start(info); + + append_key(CR_RETURNED_DATE_SK, info, rr->cr_returned_date_sk); + append_key(CR_RETURNED_TIME_SK, info, rr->cr_returned_time_sk); + append_key(CR_ITEM_SK, info, rr->cr_item_sk); + append_key(CR_REFUNDED_CUSTOMER_SK, info, rr->cr_refunded_customer_sk); + append_key(CR_REFUNDED_CDEMO_SK, info, rr->cr_refunded_cdemo_sk); + append_key(CR_REFUNDED_HDEMO_SK, info, rr->cr_refunded_hdemo_sk); + append_key(CR_REFUNDED_ADDR_SK, info, rr->cr_refunded_addr_sk); + append_key(CR_RETURNING_CUSTOMER_SK, info, rr->cr_returning_customer_sk); + append_key(CR_RETURNING_CDEMO_SK, info, rr->cr_returning_cdemo_sk); + append_key(CR_RETURNING_HDEMO_SK, info, rr->cr_returning_hdemo_sk); + append_key(CR_RETURNING_ADDR_SK, info, rr->cr_returning_addr_sk); + append_key(CR_CALL_CENTER_SK, info, rr->cr_call_center_sk); + append_key(CR_CATALOG_PAGE_SK, info, rr->cr_catalog_page_sk); + append_key(CR_SHIP_MODE_SK, info, rr->cr_ship_mode_sk); + append_key(CR_WAREHOUSE_SK, info, rr->cr_warehouse_sk); + append_key(CR_REASON_SK, info, rr->cr_reason_sk); + append_key(CR_ORDER_NUMBER, info, rr->cr_order_number); + append_integer(CR_PRICING_QUANTITY, info, rr->cr_pricing.quantity); + append_decimal(CR_PRICING_NET_PAID, info, &rr->cr_pricing.net_paid); + append_decimal(CR_PRICING_EXT_TAX, info, &rr->cr_pricing.ext_tax); + append_decimal( + CR_PRICING_NET_PAID_INC_TAX, info, &rr->cr_pricing.net_paid_inc_tax); + append_decimal(CR_PRICING_FEE, info, &rr->cr_pricing.fee); + append_decimal( + CR_PRICING_EXT_SHIP_COST, info, &rr->cr_pricing.ext_ship_cost); + append_decimal( + CR_PRICING_REFUNDED_CASH, info, &rr->cr_pricing.refunded_cash); + append_decimal( + CR_PRICING_REVERSED_CHARGE, info, &rr->cr_pricing.reversed_charge); + append_decimal(CR_PRICING_STORE_CREDIT, info, &rr->cr_pricing.store_credit); + append_decimal(CR_PRICING_NET_LOSS, info, &rr->cr_pricing.net_loss); + + append_row_end(info); + } + + void* info = append_info_get(info_arr, CATALOG_SALES); + append_row_start(info); + + append_key(CS_SOLD_DATE_SK, info, r->cs_sold_date_sk); + append_key(CS_SOLD_TIME_SK, info, r->cs_sold_time_sk); + append_key(CS_SHIP_DATE_SK, info, r->cs_ship_date_sk); + append_key(CS_BILL_CUSTOMER_SK, info, r->cs_bill_customer_sk); + append_key(CS_BILL_CDEMO_SK, info, r->cs_bill_cdemo_sk); + append_key(CS_BILL_HDEMO_SK, info, r->cs_bill_hdemo_sk); + append_key(CS_BILL_ADDR_SK, info, r->cs_bill_addr_sk); + append_key(CS_SHIP_CUSTOMER_SK, info, r->cs_ship_customer_sk); + append_key(CS_SHIP_CDEMO_SK, info, r->cs_ship_cdemo_sk); + append_key(CS_SHIP_HDEMO_SK, info, r->cs_ship_hdemo_sk); + append_key(CS_SHIP_ADDR_SK, info, r->cs_ship_addr_sk); + append_key(CS_CALL_CENTER_SK, info, r->cs_call_center_sk); + append_key(CS_CATALOG_PAGE_SK, info, r->cs_catalog_page_sk); + append_key(CS_SHIP_MODE_SK, info, r->cs_ship_mode_sk); + append_key(CS_WAREHOUSE_SK, info, r->cs_warehouse_sk); + append_key(CS_SOLD_ITEM_SK, info, r->cs_sold_item_sk); + append_key(CS_PROMO_SK, info, r->cs_promo_sk); + append_key(CS_ORDER_NUMBER, info, r->cs_order_number); + append_integer(CS_PRICING_QUANTITY, info, r->cs_pricing.quantity); + append_decimal( + CS_PRICING_WHOLESALE_COST, info, &r->cs_pricing.wholesale_cost); + append_decimal(CS_PRICING_LIST_PRICE, info, &r->cs_pricing.list_price); + append_decimal(CS_PRICING_SALES_PRICE, info, &r->cs_pricing.sales_price); + append_decimal( + CS_PRICING_EXT_DISCOUNT_AMOUNT, info, &r->cs_pricing.ext_discount_amt); + append_decimal( + CS_PRICING_EXT_SALES_PRICE, info, &r->cs_pricing.ext_sales_price); + append_decimal( + CS_PRICING_EXT_WHOLESALE_COST, info, &r->cs_pricing.ext_wholesale_cost); + append_decimal( + CS_PRICING_EXT_LIST_PRICE, info, &r->cs_pricing.ext_list_price); + append_decimal(CS_PRICING_EXT_TAX, info, &r->cs_pricing.ext_tax); + append_decimal(CS_PRICING_COUPON_AMT, info, &r->cs_pricing.coupon_amt); + append_decimal(CS_PRICING_EXT_SHIP_COST, info, &r->cs_pricing.ext_ship_cost); + append_decimal(CS_PRICING_NET_PAID, info, &r->cs_pricing.net_paid); + append_decimal( + CS_PRICING_NET_PAID_INC_TAX, info, &r->cs_pricing.net_paid_inc_tax); + append_decimal( + CS_PRICING_NET_PAID_INC_SHIP, info, &r->cs_pricing.net_paid_inc_ship); + append_decimal( + CS_PRICING_NET_PAID_INC_SHIP_TAX, + info, + &r->cs_pricing.net_paid_inc_ship_tax); + append_decimal(CS_PRICING_NET_PROFIT, info, &r->cs_pricing.net_profit); + + append_row_end(info); + + return; +} + +/* + * Routine: mk_catalog_sales() + * Purpose: build rows for the catalog sales table + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20020902 jms Need to link order date/time to call center record + * 20020902 jms Should promos be tied to item id? + */ +int mk_w_catalog_sales( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + int nLineitems, i; + + row_skip(CATALOG_RETURNS, (index - 1), dsdGenContext); + struct W_CATALOG_SALES_TBL* r; + r = mk_catalog_sales_master(info_arr, index, dsdGenContext); + + /* + * now we select the number of lineitems in this order, and loop through + * them, printing as we go + */ + genrand_integer( + &nLineitems, DIST_UNIFORM, 4, 14, 0, CS_ORDER_NUMBER, dsdGenContext); + for (i = 1; i <= nLineitems; i++) { + mk_detail(info_arr, 1, r, dsdGenContext); + } + + /** + * and finally return 1 since we have already printed the rows. + */ + return 0; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int vld_w_catalog_sales( + int nTable, + ds_key_t kRow, + int* Permutation, + DSDGenContext& dsdGenContext) { + int nLineitem, nMaxLineitem, i; + + row_skip(nTable, kRow - 1, dsdGenContext); + row_skip(CATALOG_RETURNS, (kRow - 1), dsdGenContext); + dsdGenContext.jDate = + skipDays(CATALOG_SALES, &dsdGenContext.kNewDateIndex, dsdGenContext); + + struct W_CATALOG_SALES_TBL* r; + r = mk_catalog_sales_master(NULL, kRow, dsdGenContext); + genrand_integer( + &nMaxLineitem, DIST_UNIFORM, 4, 14, 9, CS_ORDER_NUMBER, dsdGenContext); + genrand_integer( + &nLineitem, + DIST_UNIFORM, + 1, + nMaxLineitem, + 0, + CS_PRICING_QUANTITY, + dsdGenContext); + for (i = 1; i < nLineitem; i++) { + mk_detail(NULL, 0, r, dsdGenContext); + } + mk_detail(NULL, 1, r, dsdGenContext); + + return (0); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_customer.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_customer.cpp new file mode 100644 index 0000000000000..b9cd8682d7106 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_customer.cpp @@ -0,0 +1,164 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_customer.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "constants.h" +#include "genrand.h" +#include "nulls.h" +#include "porting.h" +#include "tables.h" +#include "tdefs.h" + +#include +#include "parallel.h" +/* extern tdef w_tdefs[]; */ + +/* + * Routine: mk_customer + * Purpose: populate the customer dimension + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ +int mk_w_customer( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + int nTemp; + + int nBaseDate; + /* begin locals declarations */ + int nNameIndex, nGender; + struct W_CUSTOMER_TBL* r; + date_t dtTemp; + date_t dtBirthMin, dtBirthMax, dtToday, dt1YearAgo, dt10YearsAgo; + tdef* pT = getSimpleTdefsByNumber(CUSTOMER, dsdGenContext); + r = &dsdGenContext.g_w_customer; + + date_t min_date; + strtodt(&min_date, DATE_MINIMUM); + nBaseDate = dttoj(&min_date); + + strtodt(&dtBirthMax, "1992-12-31"); + strtodt(&dtBirthMin, "1924-01-01"); + strtodt(&dtToday, TODAYS_DATE); + jtodt(&dt1YearAgo, dtToday.julian - 365); + jtodt(&dt10YearsAgo, dtToday.julian - 3650); + + nullSet(&pT->kNullBitMap, C_NULLS, dsdGenContext); + r->c_customer_sk = index; + mk_bkey(&r->c_customer_id[0], index, C_CUSTOMER_ID); + genrand_integer( + &nTemp, DIST_UNIFORM, 1, 100, 0, C_PREFERRED_CUST_FLAG, dsdGenContext); + r->c_preferred_cust_flag = (nTemp < C_PREFERRED_PCT) ? 1 : 0; + + /* demographic keys are a composite of values. rebuild them a la + * bitmap_to_dist */ + r->c_current_hdemo_sk = + mk_join(C_CURRENT_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1, dsdGenContext); + + r->c_current_cdemo_sk = + mk_join(C_CURRENT_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1, dsdGenContext); + + r->c_current_addr_sk = mk_join( + C_CURRENT_ADDR_SK, CUSTOMER_ADDRESS, r->c_customer_sk, dsdGenContext); + nNameIndex = pick_distribution( + &r->c_first_name, "first_names", 1, 3, C_FIRST_NAME, dsdGenContext); + pick_distribution( + &r->c_last_name, "last_names", 1, 1, C_LAST_NAME, dsdGenContext); + dist_weight(&nGender, "first_names", nNameIndex, 2, dsdGenContext); + pick_distribution( + &r->c_salutation, + "salutations", + 1, + (nGender == 0) ? 2 : 3, + C_SALUTATION, + dsdGenContext); + + genrand_date( + &dtTemp, + DIST_UNIFORM, + &dtBirthMin, + &dtBirthMax, + NULL, + C_BIRTH_DAY, + dsdGenContext); + r->c_birth_day = dtTemp.day; + r->c_birth_month = dtTemp.month; + r->c_birth_year = dtTemp.year; + genrand_email( + r->c_email_address, + r->c_first_name, + r->c_last_name, + C_EMAIL_ADDRESS, + dsdGenContext); + genrand_date( + &dtTemp, + DIST_UNIFORM, + &dt1YearAgo, + &dtToday, + NULL, + C_LAST_REVIEW_DATE, + dsdGenContext); + r->c_last_review_date = dtTemp.julian; + genrand_date( + &dtTemp, + DIST_UNIFORM, + &dt10YearsAgo, + &dtToday, + NULL, + C_FIRST_SALES_DATE_ID, + dsdGenContext); + r->c_first_sales_date_id = dtTemp.julian; + r->c_first_shipto_date_id = r->c_first_sales_date_id + 30; + + pick_distribution( + &r->c_birth_country, "countries", 1, 1, C_BIRTH_COUNTRY, dsdGenContext); + + void* info = append_info_get(info_arr, CUSTOMER); + append_row_start(info); + + append_key(C_CUSTOMER_SK, info, r->c_customer_sk); + append_varchar(C_CUSTOMER_ID, info, r->c_customer_id); + append_key(C_CURRENT_CDEMO_SK, info, r->c_current_cdemo_sk); + append_key(C_CURRENT_HDEMO_SK, info, r->c_current_hdemo_sk); + append_key(C_CURRENT_ADDR_SK, info, r->c_current_addr_sk); + append_key(C_FIRST_SHIPTO_DATE_ID, info, r->c_first_shipto_date_id); + append_key(C_FIRST_SALES_DATE_ID, info, r->c_first_sales_date_id); + append_varchar(C_SALUTATION, info, r->c_salutation); + append_varchar(C_FIRST_NAME, info, r->c_first_name); + append_varchar(C_LAST_NAME, info, r->c_last_name); + append_varchar( + C_PREFERRED_CUST_FLAG, info, r->c_preferred_cust_flag ? "Y" : "N"); + append_integer(C_BIRTH_DAY, info, r->c_birth_day); + append_integer(C_BIRTH_MONTH, info, r->c_birth_month); + append_integer(C_BIRTH_YEAR, info, r->c_birth_year); + append_varchar(C_BIRTH_COUNTRY, info, r->c_birth_country); + append_varchar(C_LOGIN, info, &r->c_login[0]); + append_varchar(C_EMAIL_ADDRESS, info, &r->c_email_address[0]); + append_key(C_LAST_REVIEW_DATE, info, r->c_last_review_date); + + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_customer_address.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_customer_address.cpp new file mode 100644 index 0000000000000..67fa7375d9eb1 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_customer_address.cpp @@ -0,0 +1,86 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_customer_address.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "date.h" +#include "decimal.h" +#include "genrand.h" +#include "nulls.h" +#include "porting.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * mk_customer_address + */ +int mk_w_customer_address( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + /* begin locals declarations */ + struct W_CUSTOMER_ADDRESS_TBL* r; + tdef* pTdef = getSimpleTdefsByNumber(CUSTOMER_ADDRESS, dsdGenContext); + + r = &dsdGenContext.g_w_customer_address; + + nullSet(&pTdef->kNullBitMap, CA_NULLS, dsdGenContext); + r->ca_addr_sk = index; + mk_bkey(&r->ca_addr_id[0], index, CA_ADDRESS_ID); + pick_distribution( + &r->ca_location_type, + "location_type", + 1, + 1, + CA_LOCATION_TYPE, + dsdGenContext); + mk_address(&r->ca_address, CA_ADDRESS, dsdGenContext); + + void* info = append_info_get(info_arr, CUSTOMER_ADDRESS); + append_row_start(info); + + char szTemp[128]; + + append_key(CA_ADDRESS_SK, info, r->ca_addr_sk); + append_varchar(CA_ADDRESS_ID, info, r->ca_addr_id); + append_varchar( + CA_ADDRESS_STREET_NUM, info, std::to_string(r->ca_address.street_num)); + if (r->ca_address.street_name2) { + snprintf( + szTemp, + sizeof(szTemp), + "%s %s", + r->ca_address.street_name1, + r->ca_address.street_name2); + append_varchar(CA_ADDRESS_STREET_NAME1, info, szTemp); + } else + append_varchar(CA_ADDRESS_STREET_NAME1, info, r->ca_address.street_name1); + append_varchar(CA_ADDRESS_STREET_TYPE, info, r->ca_address.street_type); + append_varchar(CA_ADDRESS_SUITE_NUM, info, &r->ca_address.suite_num[0]); + append_varchar(CA_ADDRESS_CITY, info, r->ca_address.city); + append_varchar(CA_ADDRESS_COUNTY, info, r->ca_address.county); + append_varchar(CA_ADDRESS_STATE, info, r->ca_address.state); + snprintf(szTemp, sizeof(szTemp), "%05d", r->ca_address.zip); + append_varchar(CA_ADDRESS_ZIP, info, szTemp); + append_varchar(CA_ADDRESS_COUNTRY, info, &r->ca_address.country[0]); + append_integer_decimal(CA_ADDRESS_GMT_OFFSET, info, r->ca_address.gmt_offset); + append_varchar(CA_LOCATION_TYPE, info, r->ca_location_type); + + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_customer_demographics.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_customer_demographics.cpp new file mode 100644 index 0000000000000..4b064431925cc --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_customer_demographics.cpp @@ -0,0 +1,99 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_customer_demographics.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "constants.h" +#include "genrand.h" +#include "nulls.h" +#include "porting.h" +#include "sparse.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * mk_customer_demographics + */ +int mk_w_customer_demographics( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + struct W_CUSTOMER_DEMOGRAPHICS_TBL* r; + ds_key_t kTemp; + tdef* pTdef = getSimpleTdefsByNumber(CUSTOMER_DEMOGRAPHICS, dsdGenContext); + + r = &dsdGenContext.g_w_customer_demographics; + + nullSet(&pTdef->kNullBitMap, CD_NULLS, dsdGenContext); + r->cd_demo_sk = index; + kTemp = r->cd_demo_sk - 1; + bitmap_to_dist( + &r->cd_gender, "gender", &kTemp, 1, CUSTOMER_DEMOGRAPHICS, dsdGenContext); + bitmap_to_dist( + &r->cd_marital_status, + "marital_status", + &kTemp, + 1, + CUSTOMER_DEMOGRAPHICS, + dsdGenContext); + bitmap_to_dist( + &r->cd_education_status, + "education", + &kTemp, + 1, + CUSTOMER_DEMOGRAPHICS, + dsdGenContext); + bitmap_to_dist( + &r->cd_purchase_estimate, + "purchase_band", + &kTemp, + 1, + CUSTOMER_DEMOGRAPHICS, + dsdGenContext); + bitmap_to_dist( + &r->cd_credit_rating, + "credit_rating", + &kTemp, + 1, + CUSTOMER_DEMOGRAPHICS, + dsdGenContext); + r->cd_dep_count = + static_cast((kTemp % static_cast(CD_MAX_CHILDREN))); + kTemp /= static_cast(CD_MAX_CHILDREN); + r->cd_dep_employed_count = + static_cast((kTemp % static_cast(CD_MAX_EMPLOYED))); + kTemp /= static_cast(CD_MAX_EMPLOYED); + r->cd_dep_college_count = + static_cast((kTemp % static_cast(CD_MAX_COLLEGE))); + + void* info = append_info_get(info_arr, CUSTOMER_DEMOGRAPHICS); + append_row_start(info); + + append_key(CD_DEMO_SK, info, r->cd_demo_sk); + append_varchar(CD_GENDER, info, r->cd_gender); + append_varchar(CD_MARITAL_STATUS, info, r->cd_marital_status); + append_varchar(CD_EDUCATION_STATUS, info, r->cd_education_status); + append_integer(CD_PURCHASE_ESTIMATE, info, r->cd_purchase_estimate); + append_varchar(CD_CREDIT_RATING, info, r->cd_credit_rating); + append_integer(CD_DEP_COUNT, info, r->cd_dep_count); + append_integer(CD_DEP_EMPLOYED_COUNT, info, r->cd_dep_employed_count); + append_integer(CD_DEP_COLLEGE_COUNT, info, r->cd_dep_college_count); + + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_datetbl.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_datetbl.cpp new file mode 100644 index 0000000000000..68817158b8d3d --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_datetbl.cpp @@ -0,0 +1,159 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_datetbl.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "genrand.h" +#include "nulls.h" +#include "parallel.h" +#include "porting.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* extern tdef w_tdefs[]; */ + +/* + * Routine: mk_datetbl + * Purpose: populate the date dimension + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ +int mk_w_date(void* info_arr, ds_key_t index, DSDGenContext& dsdGenContext) { + int res = 0; + + /* begin locals declarations */ + date_t base_date; + int day_index, nTemp; + date_t temp_date, dTemp2; + struct W_DATE_TBL* r; + tdef* pT = getSimpleTdefsByNumber(DATET, dsdGenContext); + + r = &dsdGenContext.g_w_date; + + if (!dsdGenContext.mk_w_date_init) { + r->d_month_seq = 0; + r->d_week_seq = 1; + r->d_quarter_seq = 1; + r->d_current_month = 0; + r->d_current_quarter = 0; + r->d_current_week = 0; + strtodt(&base_date, "1900-01-01"); + /* Make exceptions to the 1-rng-call-per-row rule */ + dsdGenContext.mk_w_date_init = 1; + } else { + strtodt(&base_date, "1900-01-01"); + } + + nullSet(&pT->kNullBitMap, D_NULLS, dsdGenContext); + nTemp = static_cast(index + base_date.julian); + r->d_date_sk = nTemp; + mk_bkey(&r->d_date_id[0], nTemp, D_DATE_ID); + jtodt(&temp_date, nTemp); + r->d_year = temp_date.year; + r->d_dow = set_dow(&temp_date); + r->d_moy = temp_date.month; + r->d_dom = temp_date.day; + /* set the sequence counts; assumes that the date table starts on a year + * boundary */ + r->d_week_seq = (static_cast(index + 6)) / 7; + r->d_month_seq = (r->d_year - 1900) * 12 + r->d_moy - 1; + r->d_quarter_seq = (r->d_year - 1900) * 4 + r->d_moy / 3 + 1; + day_index = day_number(&temp_date); + dist_member(&r->d_qoy, "calendar", day_index, 6, dsdGenContext); + /* fiscal year is identical to calendar year */ + r->d_fy_year = r->d_year; + r->d_fy_quarter_seq = r->d_quarter_seq; + r->d_fy_week_seq = r->d_week_seq; + r->d_day_name = weekday_names[r->d_dow + 1]; + dist_member(&r->d_holiday, "calendar", day_index, 8, dsdGenContext); + if ((r->d_dow == 5) || (r->d_dow == 6)) + r->d_weekend = 1; + else + r->d_weekend = 0; + if (day_index == 1) + dist_member( + &r->d_following_holiday, + "calendar", + 365 + is_leap(r->d_year - 1), + 8, + dsdGenContext); + else + dist_member( + &r->d_following_holiday, "calendar", day_index - 1, 8, dsdGenContext); + date_t_op(&dTemp2, OP_FIRST_DOM, &temp_date, 0); + r->d_first_dom = dTemp2.julian; + date_t_op(&dTemp2, OP_LAST_DOM, &temp_date, 0); + r->d_last_dom = dTemp2.julian; + date_t_op(&dTemp2, OP_SAME_LY, &temp_date, 0); + r->d_same_day_ly = dTemp2.julian; + date_t_op(&dTemp2, OP_SAME_LQ, &temp_date, 0); + r->d_same_day_lq = dTemp2.julian; + r->d_current_day = (r->d_date_sk == CURRENT_DAY) ? 1 : 0; + r->d_current_year = (r->d_year == CURRENT_YEAR) ? 1 : 0; + if (r->d_current_year) { + r->d_current_month = (r->d_moy == CURRENT_MONTH) ? 1 : 0; + r->d_current_quarter = (r->d_qoy == CURRENT_QUARTER) ? 1 : 0; + r->d_current_week = (r->d_week_seq == CURRENT_WEEK) ? 1 : 0; + } + + char sQuarterName[7]; + + void* info = append_info_get(info_arr, DATET); + append_row_start(info); + + append_key(D_DATE_SK, info, r->d_date_sk); + append_varchar(D_DATE_ID, info, r->d_date_id); + append_date(D_DATE_SK, info, r->d_date_sk); + append_integer(D_MONTH_SEQ, info, r->d_month_seq); + append_integer(D_WEEK_SEQ, info, r->d_week_seq); + append_integer(D_QUARTER_SEQ, info, r->d_quarter_seq); + append_integer(D_YEAR, info, r->d_year); + append_integer(D_DOW, info, r->d_dow); + append_integer(D_MOY, info, r->d_moy); + append_integer(D_DOM, info, r->d_dom); + append_integer(D_QOY, info, r->d_qoy); + append_integer(D_FY_YEAR, info, r->d_fy_year); + append_integer(D_FY_QUARTER_SEQ, info, r->d_fy_quarter_seq); + append_integer(D_FY_WEEK_SEQ, info, r->d_fy_week_seq); + append_varchar(D_DAY_NAME, info, r->d_day_name); + snprintf(sQuarterName, sizeof(sQuarterName), "%4dQ%d", r->d_year, r->d_qoy); + append_varchar(D_QUARTER_NAME, info, sQuarterName); + append_varchar(D_HOLIDAY, info, r->d_holiday ? "Y" : "N"); + append_varchar(D_WEEKEND, info, r->d_weekend ? "Y" : "N"); + append_varchar(D_FOLLOWING_HOLIDAY, info, r->d_following_holiday ? "Y" : "N"); + append_integer(D_FIRST_DOM, info, r->d_first_dom); + append_integer(D_LAST_DOM, info, r->d_last_dom); + append_integer(D_SAME_DAY_LY, info, r->d_same_day_ly); + append_integer(D_SAME_DAY_LQ, info, r->d_same_day_lq); + append_varchar(D_CURRENT_DAY, info, r->d_current_day ? "Y" : "N"); + append_varchar(D_CURRENT_WEEK, info, r->d_current_week ? "Y" : "N"); + append_varchar(D_CURRENT_MONTH, info, r->d_current_month ? "Y" : "N"); + append_varchar(D_CURRENT_QUARTER, info, r->d_current_quarter ? "Y" : "N"); + append_varchar(D_CURRENT_YEAR, info, r->d_current_year ? "Y" : "N"); + + append_row_end(info); + + return (res); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_household_demographics.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_household_demographics.cpp new file mode 100644 index 0000000000000..6d3d0a2350bc4 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_household_demographics.cpp @@ -0,0 +1,78 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_household_demographics.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "genrand.h" +#include "nulls.h" +#include "porting.h" +#include "sparse.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * mk_household_demographics + */ +int mk_w_household_demographics( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + /* begin locals declarations */ + ds_key_t nTemp; + struct W_HOUSEHOLD_DEMOGRAPHICS_TBL* r; + tdef* pTdef = getSimpleTdefsByNumber(HOUSEHOLD_DEMOGRAPHICS, dsdGenContext); + + r = &dsdGenContext.g_w_household_demographics; + + nullSet(&pTdef->kNullBitMap, HD_NULLS, dsdGenContext); + r->hd_demo_sk = index; + nTemp = r->hd_demo_sk; + r->hd_income_band_id = (nTemp % distsize("income_band", dsdGenContext)) + 1; + nTemp /= distsize("income_band", dsdGenContext); + bitmap_to_dist( + &r->hd_buy_potential, + "buy_potential", + &nTemp, + 1, + HOUSEHOLD_DEMOGRAPHICS, + dsdGenContext); + bitmap_to_dist( + &r->hd_dep_count, + "dependent_count", + &nTemp, + 1, + HOUSEHOLD_DEMOGRAPHICS, + dsdGenContext); + bitmap_to_dist( + &r->hd_vehicle_count, + "vehicle_count", + &nTemp, + 1, + HOUSEHOLD_DEMOGRAPHICS, + dsdGenContext); + + void* info = append_info_get(info_arr, HOUSEHOLD_DEMOGRAPHICS); + append_row_start(info); + append_key(HD_DEMO_SK, info, r->hd_demo_sk); + append_key(HD_INCOME_BAND_ID, info, r->hd_income_band_id); + append_varchar(HD_BUY_POTENTIAL, info, r->hd_buy_potential); + append_integer(HD_DEP_COUNT, info, r->hd_dep_count); + append_integer(HD_VEHICLE_COUNT, info, r->hd_vehicle_count); + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_income_band.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_income_band.cpp new file mode 100644 index 0000000000000..e354e7c592e2f --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_income_band.cpp @@ -0,0 +1,61 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_income_band.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "genrand.h" +#include "nulls.h" +#include "porting.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * mk_income_band + */ +int mk_w_income_band( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + struct W_INCOME_BAND_TBL* r; + tdef* pTdef = getSimpleTdefsByNumber(INCOME_BAND, dsdGenContext); + + r = &dsdGenContext.g_w_income_band; + + nullSet(&pTdef->kNullBitMap, IB_NULLS, dsdGenContext); + r->ib_income_band_id = static_cast(index); + dist_member( + &r->ib_lower_bound, + "income_band", + static_cast(index), + 1, + dsdGenContext); + dist_member( + &r->ib_upper_bound, + "income_band", + static_cast(index), + 2, + dsdGenContext); + + void* info = append_info_get(info_arr, INCOME_BAND); + append_row_start(info); + append_key(IB_INCOME_BAND_ID, info, r->ib_income_band_id); + append_integer(IB_LOWER_BOUND, info, r->ib_lower_bound); + append_integer(IB_UPPER_BOUND, info, r->ib_upper_bound); + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_inventory.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_inventory.cpp new file mode 100644 index 0000000000000..f0544a73c751e --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_inventory.cpp @@ -0,0 +1,137 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_inventory.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "constants.h" +#include "date.h" +#include "genrand.h" +#include "nulls.h" +#include "porting.h" +#include "scaling.h" +#include "scd.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int mk_w_inventory( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + struct W_INVENTORY_TBL* r; + ds_key_t item_count; + ds_key_t warehouse_count; + int jDate; + date_t base_date_storage; + date_t* base_date = &base_date_storage; + int nTemp; + tdef* pTdef = getSimpleTdefsByNumber(INVENTORY, dsdGenContext); + + r = &dsdGenContext.g_w_inventory; + + if (!dsdGenContext.mk_w_promotion_init) { + memset(&dsdGenContext.g_w_inventory, 0, sizeof(struct W_INVENTORY_TBL)); + dsdGenContext.mk_w_promotion_init = 1; + } + item_count = getIDCount(ITEM, dsdGenContext); + warehouse_count = get_rowcount(WAREHOUSE, dsdGenContext); + strtodt(base_date, DATE_MINIMUM); + jDate = base_date->julian; + set_dow(base_date); + /* Make exceptions to the 1-rng-call-per-row rule */ + + nullSet(&pTdef->kNullBitMap, INV_NULLS, dsdGenContext); + nTemp = static_cast(index - 1); + r->inv_item_sk = (nTemp % item_count) + 1; + nTemp /= static_cast(item_count); + r->inv_warehouse_sk = (nTemp % warehouse_count) + 1; + nTemp /= static_cast(warehouse_count); + r->inv_date_sk = jDate + (nTemp * 7); /* inventory is updated weekly */ + + /* + * the join between item and inventory is tricky. The item_id selected above + * identifies a unique part num but item is an SCD, so we need to account + * for that in selecting the SK to join with + */ + r->inv_item_sk = + matchSCDSK(r->inv_item_sk, r->inv_date_sk, ITEM, dsdGenContext); + + genrand_integer( + &r->inv_quantity_on_hand, + DIST_UNIFORM, + INV_QUANTITY_MIN, + INV_QUANTITY_MAX, + 0, + INV_QUANTITY_ON_HAND, + dsdGenContext); + + void* info = append_info_get(info_arr, INVENTORY); + append_row_start(info); + append_key(INV_DATE_SK, info, r->inv_date_sk); + append_key(INV_ITEM_SK, info, r->inv_item_sk); + append_key(INV_WAREHOUSE_SK, info, r->inv_warehouse_sk); + append_integer(INV_QUANTITY_ON_HAND, info, r->inv_quantity_on_hand); + append_row_end(info); + + return 0; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +ds_key_t sc_w_inventory(int nScale, DSDGenContext& dsdGenContext) { + ds_key_t kRes; + date_t dTemp; + int nDays; + + kRes = getIDCount(ITEM, dsdGenContext); + kRes *= get_rowcount(WAREHOUSE, dsdGenContext); + strtodt(&dTemp, DATE_MAXIMUM); + nDays = dTemp.julian; + strtodt(&dTemp, DATE_MINIMUM); + nDays -= dTemp.julian; + nDays += 1; + nDays += 6; + nDays /= 7; /* each items inventory is updated weekly */ + kRes *= nDays; + + return (kRes); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_item.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_item.cpp new file mode 100644 index 0000000000000..1915ee40a9012 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_item.cpp @@ -0,0 +1,308 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_item.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "porting.h" +#include "scd.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* extern tdef w_tdefs[]; */ + +static struct W_ITEM_TBL g_OldValues; + +/* + * mk_item + */ +int mk_w_item(void* info_arr, ds_key_t index, DSDGenContext& dsdGenContext) { + /* begin locals declarations */ + decimal_t dMinPrice, dMaxPrice, dMarkdown; + decimal_t dMinMarkdown, dMaxMarkdown; + int32_t bUseSize, bFirstRecord = 0, nFieldChangeFlags, nMin, nMax, nIndex, + nTemp; + char* cp = nullptr; + struct W_ITEM_TBL* r; + struct W_ITEM_TBL* rOldValues = &g_OldValues; + char *szMinPrice = nullptr, *szMaxPrice = nullptr; + tdef* pT = getSimpleTdefsByNumber(ITEM, dsdGenContext); + + r = &dsdGenContext.g_w_item; + + strtodec(&dMinMarkdown, MIN_ITEM_MARKDOWN_PCT); + strtodec(&dMaxMarkdown, MAX_ITEM_MARKDOWN_PCT); + memset(r, 0, sizeof(struct W_ITEM_TBL)); + + /* build the new value */ + nullSet(&pT->kNullBitMap, I_NULLS, dsdGenContext); + r->i_item_sk = index; + + nIndex = pick_distribution( + &nMin, "i_manager_id", 2, 1, I_MANAGER_ID, dsdGenContext); + dist_member(&nMax, "i_manager_id", nIndex, 3, dsdGenContext); + genrand_key( + &r->i_manager_id, + DIST_UNIFORM, + static_cast(nMin), + static_cast(nMax), + 0, + I_MANAGER_ID, + dsdGenContext); + + /* if we have generated the required history for this business key and + * generate a new one then reset associated fields (e.g., rec_start_date + * minimums) + */ + if (setSCDKeys( + I_ITEM_ID, + index, + r->i_item_id, + &r->i_rec_start_date_id, + &r->i_rec_end_date_id, + dsdGenContext)) { + /* + * some fields are not changed, even when a new version of the row is + * written + */ + bFirstRecord = 1; + } + + /* + * this is where we select the random number that controls if a field + * changes from one record to the next. + */ + nFieldChangeFlags = next_random(I_SCD, dsdGenContext); + + /* the rest of the record in a history-keeping dimension can either be a new + * data value or not; use a random number and its bit pattern to determine + * which fields to replace and which to retain + */ + gen_text(r->i_item_desc, 1, RS_I_ITEM_DESC, I_ITEM_DESC, dsdGenContext); + changeSCD( + SCD_CHAR, + &r->i_item_desc, + &rOldValues->i_item_desc, + &nFieldChangeFlags, + bFirstRecord); + + nIndex = pick_distribution( + &szMinPrice, "i_current_price", 2, 1, I_CURRENT_PRICE, dsdGenContext); + dist_member(&szMaxPrice, "i_current_price", nIndex, 3, dsdGenContext); + strtodec(&dMinPrice, szMinPrice); + strtodec(&dMaxPrice, szMaxPrice); + genrand_decimal( + &r->i_current_price, + DIST_UNIFORM, + &dMinPrice, + &dMaxPrice, + NULL, + I_CURRENT_PRICE, + dsdGenContext); + changeSCD( + SCD_INT, + &r->i_current_price, + &rOldValues->i_current_price, + &nFieldChangeFlags, + bFirstRecord); + + genrand_decimal( + &dMarkdown, + DIST_UNIFORM, + &dMinMarkdown, + &dMaxMarkdown, + NULL, + I_WHOLESALE_COST, + dsdGenContext); + decimal_t_op(&r->i_wholesale_cost, OP_MULT, &r->i_current_price, &dMarkdown); + changeSCD( + SCD_DEC, + &r->i_wholesale_cost, + &rOldValues->i_wholesale_cost, + &nFieldChangeFlags, + bFirstRecord); + + hierarchy_item( + I_CATEGORY, &r->i_category_id, &r->i_category, index, dsdGenContext); + /* + * changeSCD(SCD_INT, &r->i_category_id, &rOldValues->i_category_id, + * &nFieldChangeFlags, bFirstRecord); + */ + + hierarchy_item(I_CLASS, &r->i_class_id, &r->i_class, index, dsdGenContext); + changeSCD( + SCD_KEY, + &r->i_class_id, + &rOldValues->i_class_id, + &nFieldChangeFlags, + bFirstRecord); + + cp = &r->i_brand[0]; + hierarchy_item(I_BRAND, &r->i_brand_id, &cp, index, dsdGenContext); + changeSCD( + SCD_KEY, + &r->i_brand_id, + &rOldValues->i_brand_id, + &nFieldChangeFlags, + bFirstRecord); + + /* some categories have meaningful sizes, some don't */ + if (r->i_category_id) { + dist_member( + &bUseSize, + "categories", + static_cast(r->i_category_id), + 3, + dsdGenContext); + pick_distribution( + &r->i_size, "sizes", 1, bUseSize + 2, I_SIZE, dsdGenContext); + changeSCD( + SCD_PTR, + &r->i_size, + &rOldValues->i_size, + &nFieldChangeFlags, + bFirstRecord); + } else { + bUseSize = 0; + r->i_size = NULL; + } + + nIndex = pick_distribution( + &nMin, "i_manufact_id", 2, 1, I_MANUFACT_ID, dsdGenContext); + genrand_integer( + &nTemp, + DIST_UNIFORM, + nMin, + dist_member(NULL, "i_manufact_id", nIndex, 3, dsdGenContext), + 0, + I_MANUFACT_ID, + dsdGenContext); + r->i_manufact_id = nTemp; + changeSCD( + SCD_KEY, + &r->i_manufact_id, + &rOldValues->i_manufact_id, + &nFieldChangeFlags, + bFirstRecord); + + mk_word( + r->i_manufact, + "syllables", + static_cast(r->i_manufact_id), + RS_I_MANUFACT, + ITEM, + dsdGenContext); + changeSCD( + SCD_CHAR, + &r->i_manufact, + &rOldValues->i_manufact, + &nFieldChangeFlags, + bFirstRecord); + + gen_charset( + r->i_formulation, + DIGITS, + RS_I_FORMULATION, + RS_I_FORMULATION, + I_FORMULATION, + dsdGenContext); + embed_string(r->i_formulation, "colors", 1, 2, I_FORMULATION, dsdGenContext); + changeSCD( + SCD_CHAR, + &r->i_formulation, + &rOldValues->i_formulation, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution(&r->i_color, "colors", 1, 2, I_COLOR, dsdGenContext); + changeSCD( + SCD_PTR, + &r->i_color, + &rOldValues->i_color, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution(&r->i_units, "units", 1, 1, I_UNITS, dsdGenContext); + changeSCD( + SCD_PTR, + &r->i_units, + &rOldValues->i_units, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution(&r->i_container, "container", 1, 1, ITEM, dsdGenContext); + changeSCD( + SCD_PTR, + &r->i_container, + &rOldValues->i_container, + &nFieldChangeFlags, + bFirstRecord); + + mk_word( + r->i_product_name, + "syllables", + static_cast(index), + RS_I_PRODUCT_NAME, + ITEM, + dsdGenContext); + + r->i_promo_sk = mk_join(I_PROMO_SK, PROMOTION, 1, dsdGenContext); + genrand_integer(&nTemp, DIST_UNIFORM, 1, 100, 0, I_PROMO_SK, dsdGenContext); + if (nTemp > I_PROMO_PERCENTAGE) + r->i_promo_sk = -1; + + /* + * if this is the first of a set of revisions, then baseline the old values + */ + if (bFirstRecord) + memcpy(&g_OldValues, r, sizeof(struct W_ITEM_TBL)); + + if (index == 1) + memcpy(&g_OldValues, r, sizeof(struct W_ITEM_TBL)); + + void* info = append_info_get(info_arr, ITEM); + append_row_start(info); + + append_key(I_ITEM_SK, info, r->i_item_sk); + append_varchar(I_ITEM_ID, info, r->i_item_id); + append_date(I_REC_START_DATE_ID, info, r->i_rec_start_date_id); + append_date(I_REC_END_DATE_ID, info, r->i_rec_end_date_id); + append_varchar(I_ITEM_DESC, info, r->i_item_desc); + append_decimal(I_CURRENT_PRICE, info, &r->i_current_price); + append_decimal(I_WHOLESALE_COST, info, &r->i_wholesale_cost); + append_integer(I_BRAND_ID, info, r->i_brand_id); + append_varchar(I_BRAND, info, r->i_brand); + append_integer(I_CLASS_ID, info, r->i_class_id); + append_varchar(I_CLASS, info, r->i_class); + append_integer(I_CATEGORY_ID, info, r->i_category_id); + append_varchar(I_CATEGORY, info, r->i_category); + append_integer(I_MANUFACT_ID, info, r->i_manufact_id); + append_varchar(I_MANUFACT, info, r->i_manufact); + append_varchar(I_SIZE, info, r->i_size); + append_varchar(I_FORMULATION, info, r->i_formulation); + append_varchar(I_COLOR, info, r->i_color); + append_varchar(I_UNITS, info, r->i_units); + append_varchar(I_CONTAINER, info, r->i_container); + append_integer(I_MANAGER_ID, info, r->i_manager_id); + append_varchar(I_PRODUCT_NAME, info, r->i_product_name); + + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_promotion.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_promotion.cpp new file mode 100644 index 0000000000000..65405af4c1bb6 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_promotion.cpp @@ -0,0 +1,148 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_promotion.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "porting.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * Routine: mk_promotion + * Purpose: populate the promotion table + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20020829 jms RNG usage on p_promo_name may be too large + * 20020829 jms RNG usage on P_CHANNEL_DETAILS may be too large + */ +int mk_w_promotion( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + struct W_PROMOTION_TBL* r; + + /* begin locals declarations */ + date_t start_date; + ds_key_t nTemp; + int nFlags; + tdef* pTdef = getSimpleTdefsByNumber(PROMOTION, dsdGenContext); + + r = &dsdGenContext.g_w_promotion; + + if (!dsdGenContext.mk_w_promotion_init) { + memset(&dsdGenContext.g_w_promotion, 0, sizeof(struct W_PROMOTION_TBL)); + strtodt(&start_date, DATE_MINIMUM); + dsdGenContext.mk_w_promotion_init = 1; + } else { + strtodt(&start_date, DATE_MINIMUM); + } + + nullSet(&pTdef->kNullBitMap, P_NULLS, dsdGenContext); + r->p_promo_sk = index; + mk_bkey(&r->p_promo_id[0], index, P_PROMO_ID); + nTemp = index; + r->p_start_date_id = start_date.julian + + genrand_integer(NULL, + DIST_UNIFORM, + PROMO_START_MIN, + PROMO_START_MAX, + PROMO_START_MEAN, + P_START_DATE_ID, + dsdGenContext); + r->p_end_date_id = r->p_start_date_id + + genrand_integer(NULL, + DIST_UNIFORM, + PROMO_LEN_MIN, + PROMO_LEN_MAX, + PROMO_LEN_MEAN, + P_END_DATE_ID, + dsdGenContext); + r->p_item_sk = mk_join(P_ITEM_SK, ITEM, 1, dsdGenContext); + strtodec(&r->p_cost, "1000.00"); + r->p_response_target = 1; + mk_word( + &r->p_promo_name[0], + "syllables", + static_cast(index), + PROMO_NAME_LEN, + P_PROMO_NAME, + dsdGenContext); + nFlags = static_cast(genrand_integer( + NULL, DIST_UNIFORM, 0, 511, 0, P_CHANNEL_DMAIL, dsdGenContext)); + r->p_channel_dmail = nFlags & 0x01; + nFlags <<= 1; + r->p_channel_email = nFlags & 0x01; + nFlags <<= 1; + r->p_channel_catalog = nFlags & 0x01; + nFlags <<= 1; + r->p_channel_tv = nFlags & 0x01; + nFlags <<= 1; + r->p_channel_radio = nFlags & 0x01; + nFlags <<= 1; + r->p_channel_press = nFlags & 0x01; + nFlags <<= 1; + r->p_channel_event = nFlags & 0x01; + nFlags <<= 1; + r->p_channel_demo = nFlags & 0x01; + nFlags <<= 1; + r->p_discount_active = nFlags & 0x01; + gen_text( + &r->p_channel_details[0], + PROMO_DETAIL_LEN_MIN, + PROMO_DETAIL_LEN_MAX, + P_CHANNEL_DETAILS, + dsdGenContext); + pick_distribution( + &r->p_purpose, "promo_purpose", 1, 1, P_PURPOSE, dsdGenContext); + + void* info = append_info_get(info_arr, PROMOTION); + append_row_start(info); + append_key(P_PROMO_SK, info, r->p_promo_sk); + append_varchar(P_PROMO_ID, info, r->p_promo_id); + append_key(P_START_DATE_ID, info, r->p_start_date_id); + append_key(P_END_DATE_ID, info, r->p_end_date_id); + append_key(P_ITEM_SK, info, r->p_item_sk); + append_decimal(P_COST, info, &r->p_cost); + append_integer(P_RESPONSE_TARGET, info, r->p_response_target); + append_varchar(P_PROMO_NAME, info, &r->p_promo_name[0]); + append_varchar(P_CHANNEL_DMAIL, info, r->p_channel_dmail ? "Y" : "N"); + append_varchar(P_CHANNEL_EMAIL, info, r->p_channel_email ? "Y" : "N"); + append_varchar(P_CHANNEL_CATALOG, info, r->p_channel_catalog ? "Y" : "N"); + append_varchar(P_CHANNEL_TV, info, r->p_channel_tv ? "Y" : "N"); + append_varchar(P_CHANNEL_RADIO, info, r->p_channel_radio ? "Y" : "N"); + append_varchar(P_CHANNEL_PRESS, info, r->p_channel_press ? "Y" : "N"); + append_varchar(P_CHANNEL_EVENT, info, r->p_channel_event ? "Y" : "N"); + append_varchar(P_CHANNEL_DEMO, info, r->p_channel_demo ? "Y" : "N"); + append_varchar(P_CHANNEL_DETAILS, info, &r->p_channel_details[0]); + append_varchar(P_PURPOSE, info, r->p_purpose); + append_varchar(P_DISCOUNT_ACTIVE, info, r->p_discount_active ? "Y" : "N"); + + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_reason.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_reason.cpp new file mode 100644 index 0000000000000..3d5ad8983da7f --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_reason.cpp @@ -0,0 +1,58 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_reason.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "genrand.h" +#include "nulls.h" +#include "porting.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * mk_reason + */ +int mk_w_reason(void* info_arr, ds_key_t index, DSDGenContext& dsdGenContext) { + struct W_REASON_TBL* r; + tdef* pTdef = getSimpleTdefsByNumber(REASON, dsdGenContext); + + r = &dsdGenContext.g_w_reason; + + if (!dsdGenContext.mk_w_reason_init) { + memset(&dsdGenContext.g_w_reason, 0, sizeof(struct W_REASON_TBL)); + dsdGenContext.mk_w_reason_init = 1; + } + + nullSet(&pTdef->kNullBitMap, R_NULLS, dsdGenContext); + r->r_reason_sk = index; + mk_bkey(&r->r_reason_id[0], index, R_REASON_ID); + dist_member( + &r->r_reason_description, + "return_reasons", + static_cast(index), + 1, + dsdGenContext); + + void* info = append_info_get(info_arr, REASON); + append_row_start(info); + append_key(R_REASON_SK, info, r->r_reason_sk); + append_varchar(R_REASON_ID, info, r->r_reason_id); + append_varchar(R_REASON_DESCRIPTION, info, r->r_reason_description); + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_ship_mode.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_ship_mode.cpp new file mode 100644 index 0000000000000..8acae0d0f808c --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_ship_mode.cpp @@ -0,0 +1,83 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_ship_mode.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "genrand.h" +#include "nulls.h" +#include "porting.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int mk_w_ship_mode( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext) { + struct W_SHIP_MODE_TBL* r; + ds_key_t nTemp; + tdef* pTdef = getSimpleTdefsByNumber(SHIP_MODE, dsdGenContext); + + r = &dsdGenContext.g_w_ship_mode; + + if (dsdGenContext.mk_w_ship_mode_init) { + memset(&dsdGenContext.g_w_ship_mode, 0, sizeof(struct W_SHIP_MODE_TBL)); + dsdGenContext.mk_w_ship_mode_init = 1; + } + + nullSet(&pTdef->kNullBitMap, SM_NULLS, dsdGenContext); + r->sm_ship_mode_sk = kIndex; + mk_bkey(&r->sm_ship_mode_id[0], kIndex, SM_SHIP_MODE_ID); + nTemp = static_cast(kIndex); + bitmap_to_dist( + &r->sm_type, "ship_mode_type", &nTemp, 1, SHIP_MODE, dsdGenContext); + bitmap_to_dist( + &r->sm_code, "ship_mode_code", &nTemp, 1, SHIP_MODE, dsdGenContext); + dist_member( + &r->sm_carrier, + "ship_mode_carrier", + static_cast(kIndex), + 1, + dsdGenContext); + gen_charset( + r->sm_contract, ALPHANUM, 1, RS_SM_CONTRACT, SM_CONTRACT, dsdGenContext); + + void* info = append_info_get(info_arr, SHIP_MODE); + append_row_start(info); + append_key(SM_SHIP_MODE_SK, info, r->sm_ship_mode_sk); + append_varchar(SM_SHIP_MODE_ID, info, r->sm_ship_mode_id); + append_varchar(SM_TYPE, info, r->sm_type); + append_varchar(SM_CODE, info, r->sm_code); + append_varchar(SM_CARRIER, info, r->sm_carrier); + append_varchar(SM_CONTRACT, info, &r->sm_contract[0]); + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_store.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_store.cpp new file mode 100644 index 0000000000000..012fea609f92e --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_store.cpp @@ -0,0 +1,393 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_store.h" + +#include "append_info.h" +#include "build_support.h" +#include "config.h" +#include "constants.h" +#include "date.h" +#include "decimal.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "parallel.h" +#include "porting.h" +#include "scaling.h" +#include "scd.h" +#include "tables.h" +#include "tdefs.h" + +#include +#include + +static struct W_STORE_TBL g_store_OldValues; +/* + * mk_store + */ +int mk_w_store(void* info_arr, ds_key_t index, DSDGenContext& dsdGenContext) { + int32_t nFieldChangeFlags = 0, bFirstRecord = 0; + + /* begin locals declarations */ + static decimal_t dRevMin, dRevMax; + char *sName1 = nullptr, *sName2 = nullptr, *szTemp = nullptr; + int32_t nHierarchyTotal, nStoreType, nPercentage, nDaysOpen, nMin, nMax; + static date_t tDate; + static decimal_t min_rev_growth, max_rev_growth, dMinTaxPercentage, + dMaxTaxPercentage; + struct W_STORE_TBL *r, *rOldValues = &g_store_OldValues; + tdef* pT = getSimpleTdefsByNumber(STORE, dsdGenContext); + + r = &dsdGenContext.g_w_store; + + if (!dsdGenContext.mk_w_store_init) { + nHierarchyTotal = static_cast(get_rowcount(DIVISIONS, dsdGenContext)); + nHierarchyTotal *= static_cast(get_rowcount(COMPANY, dsdGenContext)); + strtodt(&tDate, DATE_MINIMUM); + strtodec(&min_rev_growth, STORE_MIN_REV_GROWTH); + strtodec(&max_rev_growth, STORE_MAX_REV_GROWTH); + strtodec(&dRevMin, "1.00"); + strtodec(&dRevMax, "1000000.00"); + strtodec(&dMinTaxPercentage, STORE_MIN_TAX_PERCENTAGE); + strtodec(&dMaxTaxPercentage, STORE_MAX_TAX_PERCENTAGE); + + /* columns that should be dynamic */ + r->rec_end_date_id = -1; + dsdGenContext.mk_w_store_init = 1; + } + + nullSet(&pT->kNullBitMap, W_STORE_NULLS, dsdGenContext); + r->store_sk = index; + + /* if we have generated the required history for this business key and + * generate a new one then reset associate fields (e.g., rec_start_date + * minimums) + */ + if (setSCDKeys( + S_STORE_ID, + index, + r->store_id, + &r->rec_start_date_id, + &r->rec_end_date_id, + dsdGenContext)) { + bFirstRecord = 1; + } + + /* + * this is where we select the random number that controls if a field + * changes from one record to the next. + */ + nFieldChangeFlags = next_random(W_STORE_SCD, dsdGenContext); + + /* the rest of the record in a history-keeping dimension can either be a new + * data value or not; use a random number and its bit pattern to determine + * which fields to replace and which to retain + */ + nPercentage = genrand_integer( + NULL, DIST_UNIFORM, 1, 100, 0, W_STORE_CLOSED_DATE_ID, dsdGenContext); + nDaysOpen = genrand_integer( + NULL, + DIST_UNIFORM, + STORE_MIN_DAYS_OPEN, + STORE_MAX_DAYS_OPEN, + 0, + W_STORE_CLOSED_DATE_ID, + dsdGenContext); + if (nPercentage < STORE_CLOSED_PCT) + r->closed_date_id = tDate.julian + nDaysOpen; + else + r->closed_date_id = -1; + changeSCD( + SCD_KEY, + &r->closed_date_id, + &rOldValues->closed_date_id, + &nFieldChangeFlags, + bFirstRecord); + if (!r->closed_date_id) + r->closed_date_id = -1; /* dates use a special NULL indicator */ + + mk_word( + r->store_name, + "syllables", + static_cast(index), + 5, + W_STORE_NAME, + dsdGenContext); + changeSCD( + SCD_CHAR, + &r->store_name, + &rOldValues->store_name, + &nFieldChangeFlags, + bFirstRecord); + + /* + * use the store type to set the parameters for the rest of the attributes + */ + nStoreType = pick_distribution( + &szTemp, "store_type", 1, 1, W_STORE_TYPE, dsdGenContext); + dist_member(&nMin, "store_type", nStoreType, 2, dsdGenContext); + dist_member(&nMax, "store_type", nStoreType, 3, dsdGenContext); + genrand_integer( + &r->employees, + DIST_UNIFORM, + nMin, + nMax, + 0, + W_STORE_EMPLOYEES, + dsdGenContext); + changeSCD( + SCD_INT, + &r->employees, + &rOldValues->employees, + &nFieldChangeFlags, + bFirstRecord); + + dist_member(&nMin, "store_type", nStoreType, 4, dsdGenContext); + dist_member(&nMax, "store_type", nStoreType, 5, dsdGenContext), + genrand_integer( + &r->floor_space, + DIST_UNIFORM, + nMin, + nMax, + 0, + W_STORE_FLOOR_SPACE, + dsdGenContext); + changeSCD( + SCD_INT, + &r->floor_space, + &rOldValues->floor_space, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution( + &r->hours, "call_center_hours", 1, 1, W_STORE_HOURS, dsdGenContext); + changeSCD( + SCD_PTR, &r->hours, &rOldValues->hours, &nFieldChangeFlags, bFirstRecord); + + pick_distribution( + &sName1, "first_names", 1, 1, W_STORE_MANAGER, dsdGenContext); + pick_distribution( + &sName2, "last_names", 1, 1, W_STORE_MANAGER, dsdGenContext); + snprintf(r->store_manager, sizeof(r->store_manager), "%s %s", sName1, sName2); + changeSCD( + SCD_CHAR, + &r->store_manager, + &rOldValues->store_manager, + &nFieldChangeFlags, + bFirstRecord); + + r->market_id = genrand_integer( + NULL, DIST_UNIFORM, 1, 10, 0, W_STORE_MARKET_ID, dsdGenContext); + changeSCD( + SCD_INT, + &r->market_id, + &rOldValues->market_id, + &nFieldChangeFlags, + bFirstRecord); + + genrand_decimal( + &r->dTaxPercentage, + DIST_UNIFORM, + &dMinTaxPercentage, + &dMaxTaxPercentage, + NULL, + W_STORE_TAX_PERCENTAGE, + dsdGenContext); + changeSCD( + SCD_DEC, + &r->dTaxPercentage, + &rOldValues->dTaxPercentage, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution( + &r->geography_class, + "geography_class", + 1, + 1, + W_STORE_GEOGRAPHY_CLASS, + dsdGenContext); + changeSCD( + SCD_PTR, + &r->geography_class, + &rOldValues->geography_class, + &nFieldChangeFlags, + bFirstRecord); + + gen_text( + &r->market_desc[0], + STORE_DESC_MIN, + RS_S_MARKET_DESC, + W_STORE_MARKET_DESC, + dsdGenContext); + changeSCD( + SCD_CHAR, + &r->market_desc, + &rOldValues->market_desc, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution( + &sName1, "first_names", 1, 1, W_STORE_MARKET_MANAGER, dsdGenContext); + pick_distribution( + &sName2, "last_names", 1, 1, W_STORE_MARKET_MANAGER, dsdGenContext); + snprintf( + r->market_manager, sizeof(r->market_manager), "%s %s", sName1, sName2); + changeSCD( + SCD_CHAR, + &r->market_manager, + &rOldValues->market_manager, + &nFieldChangeFlags, + bFirstRecord); + + r->division_id = pick_distribution( + &r->division_name, + "divisions", + 1, + 1, + W_STORE_DIVISION_NAME, + dsdGenContext); + changeSCD( + SCD_KEY, + &r->division_id, + &rOldValues->division_id, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->division_name, + &rOldValues->division_name, + &nFieldChangeFlags, + bFirstRecord); + + r->company_id = pick_distribution( + &r->company_name, "stores", 1, 1, W_STORE_COMPANY_NAME, dsdGenContext); + changeSCD( + SCD_KEY, + &r->company_id, + &rOldValues->company_id, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->company_name, + &rOldValues->company_name, + &nFieldChangeFlags, + bFirstRecord); + + mk_address(&r->address, W_STORE_ADDRESS, dsdGenContext); + changeSCD( + SCD_PTR, + &r->address.city, + &rOldValues->address.city, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->address.county, + &rOldValues->address.county, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_INT, + &r->address.gmt_offset, + &rOldValues->address.gmt_offset, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->address.state, + &rOldValues->address.state, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->address.street_type, + &rOldValues->address.street_type, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->address.street_name1, + &rOldValues->address.street_name1, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->address.street_name2, + &rOldValues->address.street_name2, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_INT, + &r->address.street_num, + &rOldValues->address.street_num, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_INT, + &r->address.zip, + &rOldValues->address.zip, + &nFieldChangeFlags, + bFirstRecord); + + char szTemp2[128]; + + void* info = append_info_get(info_arr, STORE); + append_row_start(info); + + append_key(W_STORE_SK, info, r->store_sk); + append_varchar(W_STORE_ID, info, r->store_id); + append_date(W_STORE_REC_START_DATE_ID, info, r->rec_start_date_id); + append_date(W_STORE_REC_END_DATE_ID, info, r->rec_end_date_id); + append_key(W_STORE_CLOSED_DATE_ID, info, r->closed_date_id); + append_varchar(W_STORE_NAME, info, r->store_name); + append_integer(W_STORE_EMPLOYEES, info, r->employees); + append_integer(W_STORE_FLOOR_SPACE, info, r->floor_space); + append_varchar(W_STORE_HOURS, info, r->hours); + append_varchar(W_STORE_MANAGER, info, &r->store_manager[0]); + append_integer(W_STORE_MARKET_ID, info, r->market_id); + append_varchar(W_STORE_GEOGRAPHY_CLASS, info, r->geography_class); + append_varchar(W_STORE_MARKET_DESC, info, &r->market_desc[0]); + append_varchar(W_STORE_MARKET_MANAGER, info, &r->market_manager[0]); + append_integer(W_STORE_DIVISION_ID, info, r->division_id); + append_varchar(W_STORE_DIVISION_NAME, info, r->division_name); + append_integer(W_STORE_COMPANY_ID, info, r->company_id); + append_varchar(W_STORE_COMPANY_NAME, info, r->company_name); + append_varchar( + W_STORE_ADDRESS_STREET_NUM, info, std::to_string(r->address.street_num)); + if (r->address.street_name2) { + snprintf( + szTemp2, + sizeof(szTemp2), + "%s %s", + r->address.street_name1, + r->address.street_name2); + append_varchar(W_STORE_ADDRESS_STREET_NAME1, info, szTemp2); + } else + append_varchar(W_STORE_ADDRESS_STREET_NAME1, info, r->address.street_name1); + append_varchar(W_STORE_ADDRESS_STREET_TYPE, info, r->address.street_type); + append_varchar(W_STORE_ADDRESS_SUITE_NUM, info, r->address.suite_num); + append_varchar(W_STORE_ADDRESS_CITY, info, r->address.city); + append_varchar(W_STORE_ADDRESS_COUNTY, info, r->address.county); + append_varchar(W_STORE_ADDRESS_STATE, info, r->address.state); + snprintf(szTemp2, sizeof(szTemp2), "%05d", r->address.zip); + append_varchar(W_STORE_ADDRESS_ZIP, info, szTemp2); + append_varchar(W_STORE_ADDRESS_COUNTRY, info, r->address.country); + append_integer_decimal( + W_STORE_ADDRESS_GMT_OFFSET, info, r->address.gmt_offset); + append_decimal(W_STORE_TAX_PERCENTAGE, info, &r->dTaxPercentage); + + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_store_returns.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_store_returns.cpp new file mode 100644 index 0000000000000..e993c480ab9c0 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_store_returns.cpp @@ -0,0 +1,114 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_store_returns.h" +#include +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "genrand.h" +#include "nulls.h" +#include "parallel.h" +#include "porting.h" +#include "pricing.h" +#include "tables.h" +#include "tdefs.h" +#include "w_store_sales.h" + +/* + * Routine: mk_store_returns() + * Purpose: populate a return fact *sync'd with a sales fact* + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int mk_w_store_returns( + void* row, + ds_key_t index, + DSDGenContext& dsdGenContext) { + int res = 0, nTemp; + struct W_STORE_RETURNS_TBL* r; + struct W_STORE_SALES_TBL* sale = &dsdGenContext.g_w_store_sales; + tdef* pT = getSimpleTdefsByNumber(STORE_RETURNS, dsdGenContext); + + decimal_t dMin, dMax; + /* begin locals declarations */ + if (row == NULL) + r = &dsdGenContext.g_w_store_returns; + else + r = static_cast(row); + + strtodec(&dMin, "1.00"); + strtodec(&dMax, "100000.00"); + + nullSet(&pT->kNullBitMap, SR_NULLS, dsdGenContext); + /* + * Some of the information in the return is taken from the original sale + * which has been regenerated + */ + r->sr_ticket_number = sale->ss_ticket_number; + r->sr_item_sk = sale->ss_sold_item_sk; + memcpy( + static_cast(&r->sr_pricing), + static_cast(&sale->ss_pricing), + sizeof(ds_pricing_t)); + + /* + * some of the fields are conditionally taken from the sale + */ + r->sr_customer_sk = mk_join(SR_CUSTOMER_SK, CUSTOMER, 1, dsdGenContext); + if (genrand_integer( + NULL, DIST_UNIFORM, 1, 100, 0, SR_TICKET_NUMBER, dsdGenContext) < + SR_SAME_CUSTOMER) + r->sr_customer_sk = sale->ss_sold_customer_sk; + + /* + * the rest of the columns are generated for this specific return + */ + /* the items cannot be returned until they are sold; offset is handled in + * mk_join, based on sales date */ + r->sr_returned_date_sk = + mk_join(SR_RETURNED_DATE_SK, DATET, sale->ss_sold_date_sk, dsdGenContext); + genrand_integer( + &nTemp, + DIST_UNIFORM, + (8 * 3600) - 1, + (17 * 3600) - 1, + 0, + SR_RETURNED_TIME_SK, + dsdGenContext); + r->sr_returned_time_sk = nTemp; + r->sr_cdemo_sk = + mk_join(SR_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1, dsdGenContext); + r->sr_hdemo_sk = + mk_join(SR_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1, dsdGenContext); + r->sr_addr_sk = mk_join(SR_ADDR_SK, CUSTOMER_ADDRESS, 1, dsdGenContext); + r->sr_store_sk = mk_join(SR_STORE_SK, STORE, 1, dsdGenContext); + r->sr_reason_sk = mk_join(SR_REASON_SK, REASON, 1, dsdGenContext); + genrand_integer( + &r->sr_pricing.quantity, + DIST_UNIFORM, + 1, + sale->ss_pricing.quantity, + 0, + SR_PRICING, + dsdGenContext); + set_pricing(SR_PRICING, &r->sr_pricing, dsdGenContext); + + return (res); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_store_sales.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_store_sales.cpp new file mode 100644 index 0000000000000..b8448192c6005 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_store_sales.cpp @@ -0,0 +1,259 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_store_sales.h" + +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "constants.h" +#include "decimal.h" +#include "genrand.h" +#include "nulls.h" +#include "parallel.h" +#include "permute.h" +#include "porting.h" +#include "scaling.h" +#include "scd.h" +#include "tables.h" +#include "tdefs.h" +#include "w_store_returns.h" + +// ds_key_t +// skipDays(int nTable, ds_key_t* pRemainder, DSDGenContext& dsdGenContext); + +/* + * mk_store_sales + */ +W_STORE_SALES_TBL* mk_master_store_sales( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + decimal_t dMin, dMax; + int nMaxItemCount; + struct W_STORE_SALES_TBL* r; + r = &dsdGenContext.g_w_store_sales; + + if (!dsdGenContext.mk_master_store_sales_init) { + strtodec(&dMin, "1.00"); + strtodec(&dMax, "100000.00"); + nMaxItemCount = 20; + dsdGenContext.pStoreSalesItemPermutation = makePermutation( + NULL, + dsdGenContext.nStoreSalesItemCount = + static_cast(getIDCount(ITEM, dsdGenContext)), + SS_PERMUTATION, + dsdGenContext); + + dsdGenContext.mk_master_store_sales_init = 1; + } else { + strtodec(&dMin, "1.00"); + strtodec(&dMax, "100000.00"); + } + + r->ss_sold_store_sk = mk_join(SS_SOLD_STORE_SK, STORE, 1, dsdGenContext); + r->ss_sold_time_sk = mk_join(SS_SOLD_TIME_SK, TIME, 1, dsdGenContext); + r->ss_sold_date_sk = mk_join(SS_SOLD_DATE_SK, DATET, 1, dsdGenContext); + r->ss_sold_customer_sk = + mk_join(SS_SOLD_CUSTOMER_SK, CUSTOMER, 1, dsdGenContext); + r->ss_sold_cdemo_sk = + mk_join(SS_SOLD_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1, dsdGenContext); + r->ss_sold_hdemo_sk = + mk_join(SS_SOLD_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1, dsdGenContext); + r->ss_sold_addr_sk = + mk_join(SS_SOLD_ADDR_SK, CUSTOMER_ADDRESS, 1, dsdGenContext); + r->ss_ticket_number = index; + genrand_integer( + &dsdGenContext.nStoreSalesItemIndex, + DIST_UNIFORM, + 1, + dsdGenContext.nStoreSalesItemCount, + 0, + SS_SOLD_ITEM_SK, + dsdGenContext); + + return r; +} + +void mk_detail( + void* info_arr, + int bPrint, + struct W_STORE_SALES_TBL* r, + DSDGenContext& dsdGenContext) { + int nTemp; + tdef* pT = getSimpleTdefsByNumber(STORE_SALES, dsdGenContext); + + nullSet(&pT->kNullBitMap, SS_NULLS, dsdGenContext); + /* + * items need to be unique within an order + * use a sequence within the permutation + */ + if (++dsdGenContext.nStoreSalesItemIndex > dsdGenContext.nStoreSalesItemCount) + dsdGenContext.nStoreSalesItemIndex = 1; + int getperm = getPermutationEntry( + dsdGenContext.pStoreSalesItemPermutation, + dsdGenContext.nStoreSalesItemIndex); + r->ss_sold_item_sk = + matchSCDSK(getperm, r->ss_sold_date_sk, ITEM, dsdGenContext); + r->ss_sold_promo_sk = mk_join(SS_SOLD_PROMO_SK, PROMOTION, 1, dsdGenContext); + set_pricing(SS_PRICING, &r->ss_pricing, dsdGenContext); + + /** + * having gone to the trouble to make the sale, now let's see if it gets + * returned + */ + genrand_integer( + &nTemp, DIST_UNIFORM, 0, 99, 0, SR_IS_RETURNED, dsdGenContext); + if (nTemp < SR_RETURN_PCT) { + struct W_STORE_RETURNS_TBL w_web_returns; + struct W_STORE_RETURNS_TBL* rr = &w_web_returns; + mk_w_store_returns(rr, 1, dsdGenContext); + + void* info = append_info_get(info_arr, STORE_RETURNS); + append_row_start(info); + + append_key(SR_RETURNED_DATE_SK, info, rr->sr_returned_date_sk); + append_key(SR_RETURNED_TIME_SK, info, rr->sr_returned_time_sk); + append_key(SR_ITEM_SK, info, rr->sr_item_sk); + append_key(SR_CUSTOMER_SK, info, rr->sr_customer_sk); + append_key(SR_CDEMO_SK, info, rr->sr_cdemo_sk); + append_key(SR_HDEMO_SK, info, rr->sr_hdemo_sk); + append_key(SR_ADDR_SK, info, rr->sr_addr_sk); + append_key(SR_STORE_SK, info, rr->sr_store_sk); + append_key(SR_REASON_SK, info, rr->sr_reason_sk); + append_key(SR_TICKET_NUMBER, info, rr->sr_ticket_number); + append_integer(SR_PRICING_QUANTITY, info, rr->sr_pricing.quantity); + append_decimal(SR_PRICING_NET_PAID, info, &rr->sr_pricing.net_paid); + append_decimal(SR_PRICING_EXT_TAX, info, &rr->sr_pricing.ext_tax); + append_decimal( + SR_PRICING_NET_PAID_INC_TAX, info, &rr->sr_pricing.net_paid_inc_tax); + append_decimal(SR_PRICING_FEE, info, &rr->sr_pricing.fee); + append_decimal( + SR_PRICING_EXT_SHIP_COST, info, &rr->sr_pricing.ext_ship_cost); + append_decimal( + SR_PRICING_REFUNDED_CASH, info, &rr->sr_pricing.refunded_cash); + append_decimal( + SR_PRICING_REVERSED_CHARGE, info, &rr->sr_pricing.reversed_charge); + append_decimal(SR_PRICING_STORE_CREDIT, info, &rr->sr_pricing.store_credit); + append_decimal(SR_PRICING_NET_LOSS, info, &rr->sr_pricing.net_loss); + append_row_end(info); + } + + void* info = append_info_get(info_arr, STORE_SALES); + append_row_start(info); + + append_key(SS_SOLD_DATE_SK, info, r->ss_sold_date_sk); + append_key(SS_SOLD_TIME_SK, info, r->ss_sold_time_sk); + append_key(SS_SOLD_ITEM_SK, info, r->ss_sold_item_sk); + append_key(SS_SOLD_CUSTOMER_SK, info, r->ss_sold_customer_sk); + append_key(SS_SOLD_CDEMO_SK, info, r->ss_sold_cdemo_sk); + append_key(SS_SOLD_HDEMO_SK, info, r->ss_sold_hdemo_sk); + append_key(SS_SOLD_ADDR_SK, info, r->ss_sold_addr_sk); + append_key(SS_SOLD_STORE_SK, info, r->ss_sold_store_sk); + append_key(SS_SOLD_PROMO_SK, info, r->ss_sold_promo_sk); + append_key(SS_TICKET_NUMBER, info, r->ss_ticket_number); + append_integer(SS_PRICING_QUANTITY, info, r->ss_pricing.quantity); + append_decimal( + SS_PRICING_WHOLESALE_COST, info, &r->ss_pricing.wholesale_cost); + append_decimal(SS_PRICING_LIST_PRICE, info, &r->ss_pricing.list_price); + append_decimal(SS_PRICING_SALES_PRICE, info, &r->ss_pricing.sales_price); + append_decimal(SS_PRICING_COUPON_AMT, info, &r->ss_pricing.coupon_amt); + append_decimal( + SS_PRICING_EXT_SALES_PRICE, info, &r->ss_pricing.ext_sales_price); + append_decimal( + SS_PRICING_EXT_WHOLESALE_COST, info, &r->ss_pricing.ext_wholesale_cost); + append_decimal( + SS_PRICING_EXT_LIST_PRICE, info, &r->ss_pricing.ext_list_price); + append_decimal(SS_PRICING_EXT_TAX, info, &r->ss_pricing.ext_tax); + append_decimal(SS_PRICING_COUPON_AMT, info, &r->ss_pricing.coupon_amt); + append_decimal(SS_PRICING_NET_PAID, info, &r->ss_pricing.net_paid); + append_decimal( + SS_PRICING_NET_PAID_INC_TAX, info, &r->ss_pricing.net_paid_inc_tax); + append_decimal(SS_PRICING_NET_PROFIT, info, &r->ss_pricing.net_profit); + + append_row_end(info); + + return; +} + +/* + * mk_store_sales + */ +int mk_w_store_sales( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + int nLineitems, i; + row_skip(STORE_RETURNS, (index - 1), dsdGenContext); + + /* build the static portion of an order */ + struct W_STORE_SALES_TBL* r; + r = mk_master_store_sales(info_arr, index, dsdGenContext); + + /* set the number of lineitems and build them */ + genrand_integer( + &nLineitems, DIST_UNIFORM, 8, 16, 0, SS_TICKET_NUMBER, dsdGenContext); + for (i = 1; i <= nLineitems; i++) { + mk_detail(info_arr, 1, r, dsdGenContext); + } + + /** + * and finally return 1 since we have already printed the rows + */ + return 0; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int vld_w_store_sales( + int nTable, + ds_key_t kRow, + int* Permutation, + DSDGenContext& dsdGenContext) { + int nLineitem, nMaxLineitem, i; + + row_skip(nTable, kRow - 1, dsdGenContext); + row_skip(STORE_RETURNS, kRow - 1, dsdGenContext); + // dsdGenContext.jDate = + // skipDays(STORE_SALES, &dsdGenContext.kNewDateIndex, dsdGenContext); + + struct W_STORE_SALES_TBL* r; + r = mk_master_store_sales(NULL, kRow, dsdGenContext); + genrand_integer( + &nMaxLineitem, DIST_UNIFORM, 8, 16, 9, SS_TICKET_NUMBER, dsdGenContext); + genrand_integer( + &nLineitem, + DIST_UNIFORM, + 1, + nMaxLineitem, + 0, + SS_PRICING_QUANTITY, + dsdGenContext); + for (i = 1; i < nLineitem; i++) { + mk_detail(NULL, 0, r, dsdGenContext); + } + mk_detail(NULL, 1, r, dsdGenContext); + + return (0); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_timetbl.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_timetbl.cpp new file mode 100644 index 0000000000000..b06d87547821a --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_timetbl.cpp @@ -0,0 +1,70 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_timetbl.h" + +#include "append_info.h" +#include "build_support.h" +#include "config.h" +#include "constants.h" +#include "date.h" +#include "decimal.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "porting.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * mk_time + */ +int mk_w_time(void* info_arr, ds_key_t index, DSDGenContext& dsdGenContext) { + /* begin locals declarations */ + int nTemp; + struct W_TIME_TBL* r; + tdef* pT = getSimpleTdefsByNumber(TIME, dsdGenContext); + + r = &dsdGenContext.g_w_time; + + nullSet(&pT->kNullBitMap, T_NULLS, dsdGenContext); + r->t_time_sk = index - 1; + mk_bkey(&r->t_time_id[0], index, T_TIME_ID); + r->t_time = static_cast(index - 1); + nTemp = static_cast(index - 1); + r->t_second = nTemp % 60; + nTemp /= 60; + r->t_minute = nTemp % 60; + nTemp /= 60; + r->t_hour = nTemp % 24; + dist_member(&r->t_am_pm, "hours", r->t_hour + 1, 2, dsdGenContext); + dist_member(&r->t_shift, "hours", r->t_hour + 1, 3, dsdGenContext); + dist_member(&r->t_sub_shift, "hours", r->t_hour + 1, 4, dsdGenContext); + dist_member(&r->t_meal_time, "hours", r->t_hour + 1, 5, dsdGenContext); + + void* info = append_info_get(info_arr, TIME); + append_row_start(info); + append_key(T_TIME_SK, info, r->t_time_sk); + append_varchar(T_TIME_ID, info, r->t_time_id); + append_integer(T_TIME, info, r->t_time); + append_integer(T_HOUR, info, r->t_hour); + append_integer(T_MINUTE, info, r->t_minute); + append_integer(T_SECOND, info, r->t_second); + append_varchar(T_AM_PM, info, r->t_am_pm); + append_varchar(T_SHIFT, info, r->t_shift); + append_varchar(T_SUB_SHIFT, info, r->t_sub_shift); + append_varchar(T_MEAL_TIME, info, r->t_meal_time, false); + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_warehouse.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_warehouse.cpp new file mode 100644 index 0000000000000..93651e85c6f92 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_warehouse.cpp @@ -0,0 +1,97 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_warehouse.h" + +#include "address.h" +#include "append_info.h" +#include "build_support.h" +#include "config.h" +#include "constants.h" +#include "date.h" +#include "decimal.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "porting.h" +#include "tables.h" +#include "tdefs.h" + +#include + +/* + * mk_warehouse + */ +int mk_w_warehouse( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + /* begin locals declarations */ + struct W_WAREHOUSE_TBL* r; + tdef* pT = getSimpleTdefsByNumber(WAREHOUSE, dsdGenContext); + + r = &dsdGenContext.g_w_warehouse; + + nullSet(&pT->kNullBitMap, W_NULLS, dsdGenContext); + r->w_warehouse_sk = index; + mk_bkey(&r->w_warehouse_id[0], index, W_WAREHOUSE_ID); + gen_text( + &r->w_warehouse_name[0], + W_NAME_MIN, + RS_W_WAREHOUSE_NAME, + W_WAREHOUSE_NAME, + dsdGenContext); + r->w_warehouse_sq_ft = genrand_integer( + NULL, + DIST_UNIFORM, + W_SQFT_MIN, + W_SQFT_MAX, + 0, + W_WAREHOUSE_SQ_FT, + dsdGenContext); + + mk_address(&r->w_address, W_WAREHOUSE_ADDRESS, dsdGenContext); + + char szTemp[128]; + + void* info = append_info_get(info_arr, WAREHOUSE); + append_row_start(info); + + append_key(W_WAREHOUSE_SK, info, r->w_warehouse_sk); + append_varchar(W_WAREHOUSE_ID, info, r->w_warehouse_id); + append_varchar(W_WAREHOUSE_NAME, info, &r->w_warehouse_name[0]); + append_integer(W_WAREHOUSE_SQ_FT, info, r->w_warehouse_sq_ft); + append_varchar( + W_ADDRESS_STREET_NUM, info, std::to_string(r->w_address.street_num)); + if (r->w_address.street_name2 != NULL) { + snprintf( + szTemp, + sizeof(szTemp), + "%s %s", + r->w_address.street_name1, + r->w_address.street_name2); + append_varchar(W_ADDRESS_STREET_NAME1, info, szTemp); + } else + append_varchar(W_ADDRESS_STREET_NAME1, info, r->w_address.street_name1); + append_varchar(W_ADDRESS_STREET_TYPE, info, r->w_address.street_type); + append_varchar(W_ADDRESS_SUITE_NUM, info, r->w_address.suite_num); + append_varchar(W_ADDRESS_CITY, info, r->w_address.city); + append_varchar(W_ADDRESS_COUNTY, info, r->w_address.county); + append_varchar(W_ADDRESS_STATE, info, r->w_address.state); + snprintf(szTemp, sizeof(szTemp), "%05d", r->w_address.zip); + append_varchar(W_ADDRESS_ZIP, info, szTemp); + append_varchar(W_ADDRESS_COUNTRY, info, r->w_address.country); + append_integer_decimal(W_ADDRESS_GMT_OFFSET, info, r->w_address.gmt_offset); + + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_page.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_page.cpp new file mode 100644 index 0000000000000..7b6a495533fb6 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_page.cpp @@ -0,0 +1,250 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_web_page.h" + +#include "append_info.h" +#include "build_support.h" +#include "config.h" +#include "constants.h" +#include "date.h" +#include "decimal.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "porting.h" +#include "scaling.h" +#include "scd.h" +#include "tables.h" +#include "tdefs.h" + +#include + +static struct W_WEB_PAGE_TBL g_web_page_OldValues; + +/* + * Routine: mk_web_page() + * Purpose: populate the web_page table + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + * 20020815 jms check text generation/seed usage + */ +int mk_w_web_page( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + int32_t bFirstRecord = 0, nFieldChangeFlags; + date_t dToday; + ds_key_t nConcurrent, nRevisions; + + /* begin locals declarations */ + int32_t nTemp, nAccess; + char szTemp[16]; + struct W_WEB_PAGE_TBL *r, *rOldValues = &g_web_page_OldValues; + tdef* pT = getSimpleTdefsByNumber(WEB_PAGE, dsdGenContext); + + r = &dsdGenContext.g_w_web_page; + + /* setup invariant values */ + snprintf( + szTemp, + sizeof(szTemp), + "%d-%d-%d", + CURRENT_YEAR, + CURRENT_MONTH, + CURRENT_DAY); + strtodt(&dToday, szTemp); + /* set up for the SCD handling */ + nConcurrent = + static_cast(get_rowcount(CONCURRENT_WEB_SITES, dsdGenContext)); + nRevisions = + static_cast(get_rowcount(WEB_PAGE, dsdGenContext) / nConcurrent); + + nullSet(&pT->kNullBitMap, WP_NULLS, dsdGenContext); + r->wp_page_sk = index; + + /* if we have generated the required history for this business key and + * generate a new one then reset associate fields (e.g., rec_start_date + * minimums) + */ + if (setSCDKeys( + WP_PAGE_ID, + index, + r->wp_page_id, + &r->wp_rec_start_date_id, + &r->wp_rec_end_date_id, + dsdGenContext)) { + /* + * some fields are not changed, even when a new version of the row is + * written + */ + bFirstRecord = 1; + } + + /* + * this is where we select the random number that controls if a field + * changes from one record to the next. + */ + nFieldChangeFlags = next_random(WP_SCD, dsdGenContext); + + r->wp_creation_date_sk = + mk_join(WP_CREATION_DATE_SK, DATET, index, dsdGenContext); + changeSCD( + SCD_KEY, + &r->wp_creation_date_sk, + &rOldValues->wp_creation_date_sk, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &nAccess, + DIST_UNIFORM, + 0, + WP_IDLE_TIME_MAX, + 0, + WP_ACCESS_DATE_SK, + dsdGenContext); + r->wp_access_date_sk = dToday.julian - nAccess; + changeSCD( + SCD_KEY, + &r->wp_access_date_sk, + &rOldValues->wp_access_date_sk, + &nFieldChangeFlags, + bFirstRecord); + if (r->wp_access_date_sk == 0) + r->wp_access_date_sk = -1; /* special case for dates */ + + genrand_integer( + &nTemp, DIST_UNIFORM, 0, 99, 0, WP_AUTOGEN_FLAG, dsdGenContext); + r->wp_autogen_flag = (nTemp < WP_AUTOGEN_PCT) ? 1 : 0; + changeSCD( + SCD_INT, + &r->wp_autogen_flag, + &rOldValues->wp_autogen_flag, + &nFieldChangeFlags, + bFirstRecord); + + r->wp_customer_sk = mk_join(WP_CUSTOMER_SK, CUSTOMER, 1, dsdGenContext); + changeSCD( + SCD_KEY, + &r->wp_customer_sk, + &rOldValues->wp_customer_sk, + &nFieldChangeFlags, + bFirstRecord); + + if (!r->wp_autogen_flag) + r->wp_customer_sk = -1; + + genrand_url(r->wp_url, WP_URL); + changeSCD( + SCD_CHAR, + &r->wp_url, + &rOldValues->wp_url, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution(&r->wp_type, "web_page_use", 1, 1, WP_TYPE, dsdGenContext); + changeSCD( + SCD_PTR, + &r->wp_type, + &rOldValues->wp_type, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->wp_link_count, + DIST_UNIFORM, + WP_LINK_MIN, + WP_LINK_MAX, + 0, + WP_LINK_COUNT, + dsdGenContext); + changeSCD( + SCD_INT, + &r->wp_link_count, + &rOldValues->wp_link_count, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->wp_image_count, + DIST_UNIFORM, + WP_IMAGE_MIN, + WP_IMAGE_MAX, + 0, + WP_IMAGE_COUNT, + dsdGenContext); + changeSCD( + SCD_INT, + &r->wp_image_count, + &rOldValues->wp_image_count, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->wp_max_ad_count, + DIST_UNIFORM, + WP_AD_MIN, + WP_AD_MAX, + 0, + WP_MAX_AD_COUNT, + dsdGenContext); + changeSCD( + SCD_INT, + &r->wp_max_ad_count, + &rOldValues->wp_max_ad_count, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->wp_char_count, + DIST_UNIFORM, + r->wp_link_count * 125 + r->wp_image_count * 50, + r->wp_link_count * 300 + r->wp_image_count * 150, + 0, + WP_CHAR_COUNT, + dsdGenContext); + changeSCD( + SCD_INT, + &r->wp_char_count, + &rOldValues->wp_char_count, + &nFieldChangeFlags, + bFirstRecord); + + void* info = append_info_get(info_arr, WEB_PAGE); + append_row_start(info); + + append_key(WP_PAGE_SK, info, r->wp_page_sk); + append_varchar(WP_PAGE_ID, info, r->wp_page_id); + append_date(WP_REC_START_DATE_ID, info, r->wp_rec_start_date_id); + append_date(WP_REC_END_DATE_ID, info, r->wp_rec_end_date_id); + append_key(WP_CREATION_DATE_SK, info, r->wp_creation_date_sk); + append_key(WP_ACCESS_DATE_SK, info, r->wp_access_date_sk); + append_varchar(WP_AUTOGEN_FLAG, info, r->wp_autogen_flag ? "Y" : "N"); + append_key(WP_CUSTOMER_SK, info, r->wp_customer_sk); + append_varchar(WP_URL, info, &r->wp_url[0]); + append_varchar(WP_TYPE, info, &r->wp_type[0]); + append_integer(WP_CHAR_COUNT, info, r->wp_char_count); + append_integer(WP_LINK_COUNT, info, r->wp_link_count); + append_integer(WP_IMAGE_COUNT, info, r->wp_image_count); + append_integer(WP_MAX_AD_COUNT, info, r->wp_max_ad_count); + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_returns.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_returns.cpp new file mode 100644 index 0000000000000..1d4fd92ca588d --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_returns.cpp @@ -0,0 +1,123 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_web_returns.h" +#include +#include "build_support.h" +#include "config.h" +#include "date.h" +#include "decimal.h" +#include "error_msg.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "porting.h" +#include "pricing.h" +#include "tables.h" +#include "tdefs.h" +#include "w_web_sales.h" + +/* + * Routine: mk_web_returns() + * Purpose: populate a return fact *sync'd with a sales fact* + * Algorithm: Since the returns need to be in line with a prior sale, they are + *built by a call from the mk_catalog_sales() routine, and then add + *return-related information Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int mk_w_web_returns(void* row, ds_key_t index, DSDGenContext& dsdGenContext) { + int res = 0; + + decimal_t dMin, dMax; + struct W_WEB_SALES_TBL* sale = &dsdGenContext.g_w_web_sales; + struct W_WEB_RETURNS_TBL* r; + tdef* pT = getSimpleTdefsByNumber(WEB_RETURNS, dsdGenContext); + + if (row == NULL) + r = &dsdGenContext.g_w_web_returns; + else + r = static_cast(row); + + strtodec(&dMin, "1.00"); + strtodec(&dMax, "100000.00"); + + nullSet(&pT->kNullBitMap, WR_NULLS, dsdGenContext); + + /* + * Some of the information in the return is taken from the original sale + * which has been regenerated + */ + r->wr_item_sk = sale->ws_item_sk; + r->wr_order_number = sale->ws_order_number; + memcpy( + static_cast(&r->wr_pricing), + static_cast(&sale->ws_pricing), + sizeof(ds_pricing_t)); + r->wr_web_page_sk = sale->ws_web_page_sk; + + /* + * the rest of the columns are generated for this specific return + */ + /* the items cannot be returned until they are shipped; offset is handled in + * mk_join, based on sales date */ + r->wr_returned_date_sk = + mk_join(WR_RETURNED_DATE_SK, DATET, sale->ws_ship_date_sk, dsdGenContext); + r->wr_returned_time_sk = mk_join(WR_RETURNED_TIME_SK, TIME, 1, dsdGenContext); + + /* most items are returned by the people they were shipped to, but some are + * returned by other folks + */ + r->wr_refunded_customer_sk = + mk_join(WR_REFUNDED_CUSTOMER_SK, CUSTOMER, 1, dsdGenContext); + r->wr_refunded_cdemo_sk = + mk_join(WR_REFUNDED_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1, dsdGenContext); + r->wr_refunded_hdemo_sk = + mk_join(WR_REFUNDED_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1, dsdGenContext); + r->wr_refunded_addr_sk = + mk_join(WR_REFUNDED_ADDR_SK, CUSTOMER_ADDRESS, 1, dsdGenContext); + if (genrand_integer( + NULL, + DIST_UNIFORM, + 0, + 99, + 0, + WR_RETURNING_CUSTOMER_SK, + dsdGenContext) < WS_GIFT_PCT) { + r->wr_refunded_customer_sk = sale->ws_ship_customer_sk; + r->wr_refunded_cdemo_sk = sale->ws_ship_cdemo_sk; + r->wr_refunded_hdemo_sk = sale->ws_ship_hdemo_sk; + r->wr_refunded_addr_sk = sale->ws_ship_addr_sk; + } + r->wr_returning_customer_sk = r->wr_refunded_customer_sk; + r->wr_returning_cdemo_sk = r->wr_refunded_cdemo_sk; + r->wr_returning_hdemo_sk = r->wr_refunded_hdemo_sk; + r->wr_returning_addr_sk = r->wr_refunded_addr_sk; + + r->wr_reason_sk = mk_join(WR_REASON_SK, REASON, 1, dsdGenContext); + genrand_integer( + &r->wr_pricing.quantity, + DIST_UNIFORM, + 1, + sale->ws_pricing.quantity, + 0, + WR_PRICING, + dsdGenContext); + set_pricing(WR_PRICING, &r->wr_pricing, dsdGenContext); + + return (res); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_sales.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_sales.cpp new file mode 100644 index 0000000000000..429e2d9b690d2 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_sales.cpp @@ -0,0 +1,326 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_web_sales.h" + +#include "append_info.h" +#include "build_support.h" +#include "config.h" +#include "constants.h" +#include "date.h" +#include "decimal.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "parallel.h" +#include "permute.h" +#include "porting.h" +#include "pricing.h" +#include "scaling.h" +#include "scd.h" +#include "tables.h" +#include "tdefs.h" +#include "w_web_returns.h" + +#include + +// ds_key_t +// skipDays(int nTable, ds_key_t* pRemainder, DSDGenContext& dsdGenContext); + +/* + * the validation process requires generating a single lineitem + * so the main mk_xxx routine has been split into a master record portion + * and a detail/lineitem portion. + */ +W_WEB_SALES_TBL* mk_web_sales_master( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + decimal_t dMin, dMax; + int nGiftPct; + struct W_WEB_SALES_TBL* r; + r = &dsdGenContext.g_w_web_sales; + + if (!dsdGenContext.mk_master_web_sales_init) { + dsdGenContext.pWebSalesItemPermutation = makePermutation( + NULL, + dsdGenContext.nWebSalesItemCount = + static_cast(getIDCount(ITEM, dsdGenContext)), + WS_PERMUTATION, + dsdGenContext); + dsdGenContext.mk_master_web_sales_init = 1; + } + strtodec(&dMin, "1.00"); + strtodec(&dMax, "100000.00"); + + /*** + * some attributes reamin the same for each lineitem in an order; others are + * different for each lineitem. Since the number of lineitems per order is + * static, we can use a modulo to determine when to change the semi-static + * values + */ + + r->ws_sold_date_sk = mk_join(WS_SOLD_DATE_SK, DATET, 1, dsdGenContext); + r->ws_sold_time_sk = mk_join(WS_SOLD_TIME_SK, TIME, 1, dsdGenContext); + r->ws_bill_customer_sk = + mk_join(WS_BILL_CUSTOMER_SK, CUSTOMER, 1, dsdGenContext); + r->ws_bill_cdemo_sk = + mk_join(WS_BILL_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1, dsdGenContext); + r->ws_bill_hdemo_sk = + mk_join(WS_BILL_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1, dsdGenContext); + r->ws_bill_addr_sk = + mk_join(WS_BILL_ADDR_SK, CUSTOMER_ADDRESS, 1, dsdGenContext); + + /* most orders are for the ordering customers, some are not */ + genrand_integer( + &nGiftPct, DIST_UNIFORM, 0, 99, 0, WS_SHIP_CUSTOMER_SK, dsdGenContext); + if (nGiftPct > WS_GIFT_PCT) { + r->ws_ship_customer_sk = + mk_join(WS_SHIP_CUSTOMER_SK, CUSTOMER, 2, dsdGenContext); + r->ws_ship_cdemo_sk = + mk_join(WS_SHIP_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 2, dsdGenContext); + r->ws_ship_hdemo_sk = + mk_join(WS_SHIP_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 2, dsdGenContext); + r->ws_ship_addr_sk = + mk_join(WS_SHIP_ADDR_SK, CUSTOMER_ADDRESS, 2, dsdGenContext); + } else { + r->ws_ship_customer_sk = r->ws_bill_customer_sk; + r->ws_ship_cdemo_sk = r->ws_bill_cdemo_sk; + r->ws_ship_hdemo_sk = r->ws_bill_hdemo_sk; + r->ws_ship_addr_sk = r->ws_bill_addr_sk; + } + + r->ws_order_number = index; + genrand_integer( + &dsdGenContext.nWebSalesItemIndex, + DIST_UNIFORM, + 1, + dsdGenContext.nWebSalesItemCount, + 0, + WS_ITEM_SK, + dsdGenContext); + + return r; +} + +void mk_detail( + void* info_arr, + int bPrint, + struct W_WEB_SALES_TBL* r, + DSDGenContext& dsdGenContext) { + int nShipLag, nTemp; + tdef* pT = getSimpleTdefsByNumber(WEB_SALES, dsdGenContext); + // r = &dsdGenContext.g_w_web_sales; + + nullSet(&pT->kNullBitMap, WS_NULLS, dsdGenContext); + + /* orders are shipped some number of days after they are ordered, + * and not all lineitems ship at the same time + */ + genrand_integer( + &nShipLag, + DIST_UNIFORM, + WS_MIN_SHIP_DELAY, + WS_MAX_SHIP_DELAY, + 0, + WS_SHIP_DATE_SK, + dsdGenContext); + r->ws_ship_date_sk = r->ws_sold_date_sk + nShipLag; + + if (++dsdGenContext.nWebSalesItemIndex > dsdGenContext.nWebSalesItemCount) + dsdGenContext.nWebSalesItemIndex = 1; + r->ws_item_sk = matchSCDSK( + getPermutationEntry( + dsdGenContext.pWebSalesItemPermutation, + dsdGenContext.nWebSalesItemIndex), + r->ws_sold_date_sk, + ITEM, + dsdGenContext); + + /* the web page needs to be valid for the sale date */ + r->ws_web_page_sk = + mk_join(WS_WEB_PAGE_SK, WEB_PAGE, r->ws_sold_date_sk, dsdGenContext); + r->ws_web_site_sk = + mk_join(WS_WEB_SITE_SK, WEB_SITE, r->ws_sold_date_sk, dsdGenContext); + + r->ws_ship_mode_sk = mk_join(WS_SHIP_MODE_SK, SHIP_MODE, 1, dsdGenContext); + r->ws_warehouse_sk = mk_join(WS_WAREHOUSE_SK, WAREHOUSE, 1, dsdGenContext); + r->ws_promo_sk = mk_join(WS_PROMO_SK, PROMOTION, 1, dsdGenContext); + set_pricing(WS_PRICING, &r->ws_pricing, dsdGenContext); + + /** + * having gone to the trouble to make the sale, now let's see if it gets + * returned + */ + genrand_integer( + &nTemp, DIST_UNIFORM, 0, 99, 0, WR_IS_RETURNED, dsdGenContext); + if (nTemp < WR_RETURN_PCT) { + struct W_WEB_RETURNS_TBL w_web_returns; + struct W_WEB_RETURNS_TBL* rr = &dsdGenContext.g_w_web_returns; + mk_w_web_returns(rr, 1, dsdGenContext); + + void* info = append_info_get(info_arr, WEB_RETURNS); + append_row_start(info); + + append_key(WR_RETURNED_DATE_SK, info, rr->wr_returned_date_sk); + append_key(WR_RETURNED_TIME_SK, info, rr->wr_returned_time_sk); + append_key(WR_ITEM_SK, info, rr->wr_item_sk); + append_key(WR_REFUNDED_CUSTOMER_SK, info, rr->wr_refunded_customer_sk); + append_key(WR_REFUNDED_CDEMO_SK, info, rr->wr_refunded_cdemo_sk); + append_key(WR_REFUNDED_HDEMO_SK, info, rr->wr_refunded_hdemo_sk); + append_key(WR_REFUNDED_ADDR_SK, info, rr->wr_refunded_addr_sk); + append_key(WR_RETURNING_CUSTOMER_SK, info, rr->wr_returning_customer_sk); + append_key(WR_RETURNING_CDEMO_SK, info, rr->wr_returning_cdemo_sk); + append_key(WR_RETURNING_HDEMO_SK, info, rr->wr_returning_hdemo_sk); + append_key(WR_RETURNING_ADDR_SK, info, rr->wr_returning_addr_sk); + append_key(WR_WEB_PAGE_SK, info, rr->wr_web_page_sk); + append_key(WR_REASON_SK, info, rr->wr_reason_sk); + append_key(WR_ORDER_NUMBER, info, rr->wr_order_number); + append_integer(WR_PRICING_QUANTITY, info, rr->wr_pricing.quantity); + append_decimal(WR_PRICING_NET_PAID, info, &rr->wr_pricing.net_paid); + append_decimal(WR_PRICING_EXT_TAX, info, &rr->wr_pricing.ext_tax); + append_decimal( + WR_PRICING_NET_PAID_INC_TAX, info, &rr->wr_pricing.net_paid_inc_tax); + append_decimal(WR_PRICING_FEE, info, &rr->wr_pricing.fee); + append_decimal( + WR_PRICING_EXT_SHIP_COST, info, &rr->wr_pricing.ext_ship_cost); + append_decimal( + WR_PRICING_REFUNDED_CASH, info, &rr->wr_pricing.refunded_cash); + append_decimal( + WR_PRICING_REVERSED_CHARGE, info, &rr->wr_pricing.reversed_charge); + append_decimal(WR_PRICING_STORE_CREDIT, info, &rr->wr_pricing.store_credit); + append_decimal(WR_PRICING_NET_LOSS, info, &rr->wr_pricing.net_loss); + + append_row_end(info); + } + + void* info = append_info_get(info_arr, WEB_SALES); + append_row_start(info); + + append_key(WS_SOLD_DATE_SK, info, r->ws_sold_date_sk); + append_key(WS_SOLD_TIME_SK, info, r->ws_sold_time_sk); + append_key(WS_SHIP_DATE_SK, info, r->ws_ship_date_sk); + append_key(WS_ITEM_SK, info, r->ws_item_sk); + append_key(WS_BILL_CUSTOMER_SK, info, r->ws_bill_customer_sk); + append_key(WS_BILL_CDEMO_SK, info, r->ws_bill_cdemo_sk); + append_key(WS_BILL_HDEMO_SK, info, r->ws_bill_hdemo_sk); + append_key(WS_BILL_ADDR_SK, info, r->ws_bill_addr_sk); + append_key(WS_SHIP_CUSTOMER_SK, info, r->ws_ship_customer_sk); + append_key(WS_SHIP_CDEMO_SK, info, r->ws_ship_cdemo_sk); + append_key(WS_SHIP_HDEMO_SK, info, r->ws_ship_hdemo_sk); + append_key(WS_SHIP_ADDR_SK, info, r->ws_ship_addr_sk); + append_key(WS_WEB_PAGE_SK, info, r->ws_web_page_sk); + append_key(WS_WEB_SITE_SK, info, r->ws_web_site_sk); + append_key(WS_SHIP_MODE_SK, info, r->ws_ship_mode_sk); + append_key(WS_WAREHOUSE_SK, info, r->ws_warehouse_sk); + append_key(WS_PROMO_SK, info, r->ws_promo_sk); + append_key(WS_ORDER_NUMBER, info, r->ws_order_number); + append_integer(WS_PRICING_QUANTITY, info, r->ws_pricing.quantity); + append_decimal( + WS_PRICING_WHOLESALE_COST, info, &r->ws_pricing.wholesale_cost); + append_decimal(WS_PRICING_LIST_PRICE, info, &r->ws_pricing.list_price); + append_decimal(WS_PRICING_SALES_PRICE, info, &r->ws_pricing.sales_price); + append_decimal( + WS_PRICING_EXT_DISCOUNT_AMT, info, &r->ws_pricing.ext_discount_amt); + append_decimal( + WS_PRICING_EXT_SALES_PRICE, info, &r->ws_pricing.ext_sales_price); + append_decimal( + WS_PRICING_EXT_WHOLESALE_COST, info, &r->ws_pricing.ext_wholesale_cost); + append_decimal( + WS_PRICING_EXT_LIST_PRICE, info, &r->ws_pricing.ext_list_price); + append_decimal(WS_PRICING_EXT_TAX, info, &r->ws_pricing.ext_tax); + append_decimal(WS_PRICING_COUPON_AMT, info, &r->ws_pricing.coupon_amt); + append_decimal(WS_PRICING_EXT_SHIP_COST, info, &r->ws_pricing.ext_ship_cost); + append_decimal(WS_PRICING_NET_PAID, info, &r->ws_pricing.net_paid); + append_decimal( + WS_PRICING_NET_PAID_INC_TAX, info, &r->ws_pricing.net_paid_inc_tax); + append_decimal( + WS_PRICING_NET_PAID_INC_SHIP, info, &r->ws_pricing.net_paid_inc_ship); + append_decimal( + WS_PRICING_NET_PAID_INC_SHIP_TAX, + info, + &r->ws_pricing.net_paid_inc_ship_tax); + append_decimal(WS_PRICING_NET_PROFIT, info, &r->ws_pricing.net_profit); + + append_row_end(info); + + return; +} + +/* + * mk_web_sales + */ +int mk_w_web_sales( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + int nLineitems, i; + + row_skip(WEB_RETURNS, (index - 1), dsdGenContext); + /* build the static portion of an order */ + struct W_WEB_SALES_TBL* r; + r = mk_web_sales_master(info_arr, index, dsdGenContext); + + /* set the number of lineitems and build them */ + genrand_integer( + &nLineitems, DIST_UNIFORM, 8, 16, 9, WS_ORDER_NUMBER, dsdGenContext); + for (i = 1; i <= nLineitems; i++) { + mk_detail(info_arr, 1, r, dsdGenContext); + } + + /** + * and finally return 1 since we have already printed the rows + */ + return 0; +} + +/* + * Routine: + * Purpose: + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: None + */ +int vld_web_sales( + int nTable, + ds_key_t kRow, + int* Permutation, + DSDGenContext& dsdGenContext) { + int nLineitem, nMaxLineitem, i; + + row_skip(nTable, kRow - 1, dsdGenContext); + row_skip(WEB_RETURNS, (kRow - 1), dsdGenContext); + struct W_WEB_SALES_TBL* r; + r = mk_web_sales_master(NULL, kRow, dsdGenContext); + genrand_integer( + &nMaxLineitem, DIST_UNIFORM, 8, 16, 9, WS_ORDER_NUMBER, dsdGenContext); + genrand_integer( + &nLineitem, + DIST_UNIFORM, + 1, + nMaxLineitem, + 0, + WS_PRICING_QUANTITY, + dsdGenContext); + for (i = 1; i < nLineitem; i++) { + mk_detail(NULL, 0, r, dsdGenContext); + } + mk_detail(NULL, 1, r, dsdGenContext); + + return (0); +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_site.cpp b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_site.cpp new file mode 100644 index 0000000000000..6e78ab1d6fe4c --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/dsdgen-c/w_web_site.cpp @@ -0,0 +1,313 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "w_web_site.h" + +#include "address.h" +#include "append_info.h" +#include "build_support.h" +#include "columns.h" +#include "config.h" +#include "constants.h" +#include "genrand.h" +#include "misc.h" +#include "nulls.h" +#include "porting.h" +#include "scaling.h" +#include "scd.h" +#include "tables.h" +#include "tdefs.h" + +#include + +static struct W_WEB_SITE_TBL g_OldValues; + +/* + * Routine: mk_web_site() + * Purpose: populate the web_site table + * Algorithm: + * Data Structures: + * + * Params: + * Returns: + * Called By: + * Calls: + * Assumptions: + * Side Effects: + * TODO: + */ +int mk_w_web_site( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext) { + int32_t nFieldChangeFlags, bFirstRecord = 0; + decimal_t dMinTaxPercentage, dMaxTaxPercentage; + + /* begin locals declarations */ + char szTemp[16], *sName1 = nullptr, *sName2 = nullptr; + struct W_WEB_SITE_TBL *r, *rOldValues = &g_OldValues; + tdef* pT = getSimpleTdefsByNumber(WEB_SITE, dsdGenContext); + + r = &dsdGenContext.g_w_web_site; + + snprintf( + szTemp, + sizeof(szTemp), + "%d-%d-%d", + CURRENT_YEAR, + CURRENT_MONTH, + CURRENT_DAY); + strcpy(r->web_class, "Unknown"); + strtodec(&dMinTaxPercentage, WEB_MIN_TAX_PERCENTAGE); + strtodec(&dMaxTaxPercentage, WEB_MAX_TAX_PERCENTAGE); + + nullSet(&pT->kNullBitMap, WEB_NULLS, dsdGenContext); + r->web_site_sk = index; + + /* if we have generated the required history for this business key and + * generate a new one then reset associate fields (e.g., rec_start_date + * minimums) + */ + if (setSCDKeys( + WEB_SITE_ID, + index, + r->web_site_id, + &r->web_rec_start_date_id, + &r->web_rec_end_date_id, + dsdGenContext)) { + r->web_open_date = mk_join(WEB_OPEN_DATE, DATET, index, dsdGenContext); + r->web_close_date = mk_join(WEB_CLOSE_DATE, DATET, index, dsdGenContext); + if (r->web_close_date > r->web_rec_end_date_id) + r->web_close_date = -1; + snprintf( + r->web_name, + sizeof(r->web_name), + "site_%d", + static_cast(index / 6)); + bFirstRecord = 1; + } + + /* + * this is where we select the random number that controls if a field + * changes from one record to the next. + */ + nFieldChangeFlags = next_random(WEB_SCD, dsdGenContext); + + /* the rest of the record in a history-keeping dimension can either be a new + * data value or not; use a random number and its bit pattern to determine + * which fields to replace and which to retain + */ + pick_distribution(&sName1, "first_names", 1, 1, WEB_MANAGER, dsdGenContext); + pick_distribution(&sName2, "last_names", 1, 1, WEB_MANAGER, dsdGenContext); + snprintf(r->web_manager, sizeof(r->web_manager), "%s %s", sName1, sName2); + changeSCD( + SCD_CHAR, + &r->web_manager, + &rOldValues->web_manager, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->web_market_id, DIST_UNIFORM, 1, 6, 0, WEB_MARKET_ID, dsdGenContext); + changeSCD( + SCD_INT, + &r->web_market_id, + &rOldValues->web_market_id, + &nFieldChangeFlags, + bFirstRecord); + + gen_text( + r->web_market_class, + 20, + RS_WEB_MARKET_CLASS, + WEB_MARKET_CLASS, + dsdGenContext); + changeSCD( + SCD_CHAR, + &r->web_market_class, + &rOldValues->web_market_class, + &nFieldChangeFlags, + bFirstRecord); + + gen_text( + r->web_market_desc, + 20, + RS_WEB_MARKET_DESC, + WEB_MARKET_DESC, + dsdGenContext); + changeSCD( + SCD_CHAR, + &r->web_market_desc, + &rOldValues->web_market_desc, + &nFieldChangeFlags, + bFirstRecord); + + pick_distribution( + &sName1, "first_names", 1, 1, WEB_MARKET_MANAGER, dsdGenContext); + pick_distribution( + &sName2, "last_names", 1, 1, WEB_MARKET_MANAGER, dsdGenContext); + snprintf( + r->web_market_manager, + sizeof(r->web_market_manager), + "%s %s", + sName1, + sName2); + changeSCD( + SCD_CHAR, + &r->web_market_manager, + &rOldValues->web_market_manager, + &nFieldChangeFlags, + bFirstRecord); + + genrand_integer( + &r->web_company_id, DIST_UNIFORM, 1, 6, 0, WEB_COMPANY_ID, dsdGenContext); + changeSCD( + SCD_INT, + &r->web_company_id, + &rOldValues->web_company_id, + &nFieldChangeFlags, + bFirstRecord); + + mk_word( + r->web_company_name, + "syllables", + r->web_company_id, + RS_WEB_COMPANY_NAME, + WEB_COMPANY_NAME, + dsdGenContext); + changeSCD( + SCD_CHAR, + &r->web_company_name, + &rOldValues->web_company_name, + &nFieldChangeFlags, + bFirstRecord); + + mk_address(&r->web_address, WEB_ADDRESS, dsdGenContext); + changeSCD( + SCD_PTR, + &r->web_address.city, + &rOldValues->web_address.city, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->web_address.county, + &rOldValues->web_address.county, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_INT, + &r->web_address.gmt_offset, + &rOldValues->web_address.gmt_offset, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->web_address.state, + &rOldValues->web_address.state, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->web_address.street_type, + &rOldValues->web_address.street_type, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->web_address.street_name1, + &rOldValues->web_address.street_name1, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_PTR, + &r->web_address.street_name2, + &rOldValues->web_address.street_name2, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_INT, + &r->web_address.street_num, + &rOldValues->web_address.street_num, + &nFieldChangeFlags, + bFirstRecord); + changeSCD( + SCD_INT, + &r->web_address.zip, + &rOldValues->web_address.zip, + &nFieldChangeFlags, + bFirstRecord); + + genrand_decimal( + &r->web_tax_percentage, + DIST_UNIFORM, + &dMinTaxPercentage, + &dMaxTaxPercentage, + NULL, + WEB_TAX_PERCENTAGE, + dsdGenContext); + changeSCD( + SCD_DEC, + &r->web_tax_percentage, + &rOldValues->web_tax_percentage, + &nFieldChangeFlags, + bFirstRecord); + + void* info = append_info_get(info_arr, WEB_SITE); + append_row_start(info); + + char szStreetName[128]; + + append_key(WEB_SITE_SK, info, r->web_site_sk); + append_varchar(WEB_SITE_ID, info, &r->web_site_id[0]); + append_date( + WEB_REC_START_DATE_ID, info, static_cast(r->web_rec_start_date_id)); + append_date( + WEB_REC_END_DATE_ID, info, static_cast(r->web_rec_end_date_id)); + append_varchar(WEB_NAME, info, &r->web_name[0]); + append_key(WEB_OPEN_DATE, info, r->web_open_date); + append_key(WEB_CLOSE_DATE, info, r->web_close_date); + append_varchar(WEB_CLASS, info, &r->web_class[0]); + append_varchar(WEB_MANAGER, info, &r->web_manager[0]); + append_integer(WEB_MARKET_ID, info, r->web_market_id); + append_varchar(WEB_MARKET_CLASS, info, &r->web_market_class[0]); + append_varchar(WEB_MARKET_DESC, info, &r->web_market_desc[0]); + append_varchar(WEB_MARKET_MANAGER, info, &r->web_market_manager[0]); + append_integer(WEB_COMPANY_ID, info, r->web_company_id); + append_varchar(WEB_COMPANY_NAME, info, &r->web_company_name[0]); + append_varchar( + WEB_ADDRESS_STREET_NUM, info, std::to_string(r->web_address.street_num)); + if (r->web_address.street_name2) { + snprintf( + szStreetName, + sizeof(szStreetName), + "%s %s", + r->web_address.street_name1, + r->web_address.street_name2); + append_varchar(WEB_ADDRESS_STREET_NAME1, info, szStreetName); + } else + append_varchar(WEB_ADDRESS_STREET_NAME1, info, r->web_address.street_name1); + append_varchar(WEB_ADDRESS_STREET_TYPE, info, r->web_address.street_type); + append_varchar(WEB_ADDRESS_SUITE_NUM, info, r->web_address.suite_num); + append_varchar(WEB_ADDRESS_CITY, info, r->web_address.city); + append_varchar(WEB_ADDRESS_COUNTY, info, r->web_address.county); + append_varchar(WEB_ADDRESS_STATE, info, r->web_address.state); + snprintf(szStreetName, sizeof(szStreetName), "%05d", r->web_address.zip); + append_varchar(WEB_ADDRESS_ZIP, info, szStreetName); + append_varchar(WEB_ADDRESS_COUNTRY, info, r->web_address.country); + append_integer_decimal( + WEB_ADDRESS_GMT_OFFSET, info, r->web_address.gmt_offset); + append_decimal(WEB_TAX_PERCENTAGE, info, &r->web_tax_percentage); + + append_row_end(info); + + return 0; +} diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/StringBuffer.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/StringBuffer.h new file mode 100644 index 0000000000000..c8a8b8c6fe577 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/StringBuffer.h @@ -0,0 +1,30 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef STRING_BUFFER_H +#define STRING_BUFFER_H + +#define SB_INIT 0x01 + +typedef struct STRING_BUFFER_T { + int nFlags; + int nBytesAllocated; + int nBytesUsed; + int nIncrement; + char* pText; +} StringBuffer_t; + +StringBuffer_t* InitBuffer(int nSize, int nIncrement); +int AddBuffer(StringBuffer_t* pBuf, char* pStr); +int ResetBuffer(StringBuffer_t* pBuf); +char* GetBuffer(StringBuffer_t* pBuf); +void FreeBuffer(StringBuffer_t* pBuf); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/address.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/address.h new file mode 100644 index 0000000000000..ffba8b6a2cd54 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/address.h @@ -0,0 +1,46 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef DS_ADDRESS_H +#define DS_ADDRESS_H + +#include "constants.h" +#include "dist.h" + +#define DS_ADDR_SUITE_NUM 0 +#define DS_ADDR_STREET_NUM 1 +#define DS_ADDR_STREET_NAME1 2 +#define DS_ADDR_STREET_NAME2 3 +#define DS_ADDR_STREET_TYPE 4 +#define DS_ADDR_CITY 5 +#define DS_ADDR_COUNTY 6 +#define DS_ADDR_STATE 7 +#define DS_ADDR_COUNTRY 8 +#define DS_ADDR_ZIP 9 +#define DS_ADDR_PLUS4 10 +#define DS_ADDR_GMT_OFFSET 11 + +int mk_address(ds_addr_t* pDest, int nColumn, DSDGenContext& dsdGenContext); +int mk_streetnumber(int nTable, int* dest, DSDGenContext& dsdGenContext); +int mk_suitenumber(int nTable, char* dest, DSDGenContext& dsdGenContext); +int mk_streetname(int nTable, char* dest); +int mk_city(int nTable, char** dest, DSDGenContext& dsdGenContext); +int city_hash(int nTable, char* name); +int mk_zipcode( + int nTable, + char* dest, + int nRegion, + char* city, + DSDGenContext& dsdGenContext); +// void printAddressPart(FILE *fp, ds_addr_t *pAddr, int nAddressPart); +void resetCountCount(void); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/append_info.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/append_info.h new file mode 100644 index 0000000000000..be33b5da739bc --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/append_info.h @@ -0,0 +1,44 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef R_APPEND_H +#define R_APPEND_H + +#include +#include + +#include "decimal.h" + +typedef void* append_info; + +append_info* append_info_get(void* info_list, int table_id); + +void append_row_start(append_info info); +void append_row_end(append_info info); + +void append_varchar( + int32_t column, + append_info info, + const char* value, + bool fillEmptyStringAsNull = true); +void append_varchar( + int32_t column, + append_info info, + std::string value, + bool fillEmptyStringAsNull = true); +void append_key(int32_t column, append_info info, int64_t value); +void append_date(int32_t column, append_info info, int64_t value); +void append_integer(int32_t column, append_info info, int32_t value); +void append_decimal(int32_t column, append_info info, decimal_t* val); +void append_boolean(int32_t column, append_info info, int32_t val); +void append_integer_decimal(int32_t column, append_info info, int32_t val); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/build_support.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/build_support.h new file mode 100644 index 0000000000000..316b5ce65188f --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/build_support.h @@ -0,0 +1,88 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef BUILD_SUPPORT_H +#define BUILD_SUPPORT_H + +#include "columns.h" +#include "date.h" +#include "decimal.h" +#include "dist.h" +#include "pricing.h" + +void bitmap_to_dist( + void* pDest, + const char* distname, + ds_key_t* modulus, + int vset, + int stream, + DSDGenContext& dsdGenContext); +void dist_to_bitmap( + int* pDest, + const char* szDistName, + int nValue, + int nWeight, + int nStream); +void random_to_bitmap( + int* pDest, + int nDist, + int nMin, + int nMax, + int nMean, + int nStream); +int city_hash(int nTable, char* city); +void hierarchy_item( + int h_level, + ds_key_t* id, + char** name, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); +ds_key_t mk_join( + int from_tbl, + int to_tbl, + ds_key_t ref_key, + DSDGenContext& dsdGenContext); +ds_key_t getCatalogNumberFromPage(ds_key_t kPageNumber); +void mk_word( + char* dest, + const char* syl_set, + ds_key_t src, + int char_cnt, + int col, + DSDGenContext& dsdGenContext); +int set_locale(int nRegion, decimal_t* longitude, decimal_t* latitude); +int adj_time( + ds_key_t* res_date, + ds_key_t* res_time, + ds_key_t base_date, + ds_key_t base_time, + ds_key_t offset_key, + int tabid); +void mk_bkey(char* szDest, ds_key_t kPrimary, int nStream); +int embed_string( + char* szDest, + const char* szDist, + int nValue, + int nWeight, + int nStream, + DSDGenContext& dsdGenContext); +int mk_companyname( + char* dest, + int nTable, + int nCompany, + DSDGenContext& dsdGenContext); +void setUpdateDateRange( + int nTable, + date_t* pMinDate, + date_t* pMaxDate, + DSDGenContext& dsdGenContext); + +#endif /* BUILD_SUPPORT_H */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/columns.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/columns.h new file mode 100644 index 0000000000000..8e6fc0ed4f8d7 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/columns.h @@ -0,0 +1,942 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +/* + * THIS IS A GENERATED FILE + * SEE COLUMNS.LIST + */ +#ifndef COLUMNS_H +#define COLUMNS_H +#define CALL_CENTER_START 1 +#define CC_CALL_CENTER_SK 1 +#define CC_CALL_CENTER_ID 2 +#define CC_REC_START_DATE_ID 3 +#define CC_REC_END_DATE_ID 4 +#define CC_CLOSED_DATE_ID 5 +#define CC_OPEN_DATE_ID 6 +#define CC_NAME 7 +#define CC_CLASS 8 +#define CC_EMPLOYEES 9 +#define CC_SQ_FT 10 +#define CC_HOURS 11 +#define CC_MANAGER 12 +#define CC_MARKET_ID 13 +#define CC_MARKET_CLASS 14 +#define CC_MARKET_DESC 15 +#define CC_MARKET_MANAGER 16 +#define CC_DIVISION 17 +#define CC_DIVISION_NAME 18 +#define CC_COMPANY 19 +#define CC_COMPANY_NAME 20 +#define CC_STREET_NUMBER 21 +#define CC_STREET_NAME 22 +#define CC_STREET_TYPE 23 +#define CC_SUITE_NUMBER 24 +#define CC_CITY 25 +#define CC_COUNTY 26 +#define CC_STATE 27 +#define CC_ZIP 28 +#define CC_COUNTRY 29 +#define CC_GMT_OFFSET 30 +#define CC_ADDRESS 31 +#define CC_TAX_PERCENTAGE 32 +#define CC_SCD 33 +#define CC_NULLS 34 +#define CALL_CENTER_END 34 +#define CATALOG_PAGE_START 35 +#define CP_CATALOG_PAGE_SK 35 +#define CP_CATALOG_PAGE_ID 36 +#define CP_START_DATE_ID 37 +#define CP_END_DATE_ID 38 +#define CP_PROMO_ID 39 +#define CP_DEPARTMENT 40 +#define CP_CATALOG_NUMBER 41 +#define CP_CATALOG_PAGE_NUMBER 42 +#define CP_DESCRIPTION 43 +#define CP_TYPE 44 +#define CP_NULLS 45 +#define CATALOG_PAGE_END 45 +#define CATALOG_RETURNS_START 46 +#define CR_RETURNED_DATE_SK 46 +#define CR_RETURNED_TIME_SK 47 +#define CR_ITEM_SK 48 +#define CR_REFUNDED_CUSTOMER_SK 49 +#define CR_REFUNDED_CDEMO_SK 50 +#define CR_REFUNDED_HDEMO_SK 51 +#define CR_REFUNDED_ADDR_SK 52 +#define CR_RETURNING_CUSTOMER_SK 53 +#define CR_RETURNING_CDEMO_SK 54 +#define CR_RETURNING_HDEMO_SK 55 +#define CR_RETURNING_ADDR_SK 56 +#define CR_CALL_CENTER_SK 57 +#define CR_CATALOG_PAGE_SK 58 +#define CR_SHIP_MODE_SK 59 +#define CR_WAREHOUSE_SK 60 +#define CR_REASON_SK 61 +#define CR_ORDER_NUMBER 62 +#define CR_PRICING_QUANTITY 63 +#define CR_PRICING_NET_PAID 64 +#define CR_PRICING_EXT_TAX 65 +#define CR_PRICING_NET_PAID_INC_TAX 66 +#define CR_PRICING_FEE 67 +#define CR_PRICING_EXT_SHIP_COST 68 +#define CR_PRICING_REFUNDED_CASH 69 +#define CR_PRICING_REVERSED_CHARGE 70 +#define CR_PRICING_STORE_CREDIT 71 +#define CR_PRICING_NET_LOSS 72 +#define CR_NULLS 73 +#define CR_PRICING 74 +#define CATALOG_RETURNS_END 74 +#define CATALOG_SALES_START 75 +#define CS_SOLD_DATE_SK 75 +#define CS_SOLD_TIME_SK 76 +#define CS_SHIP_DATE_SK 77 +#define CS_BILL_CUSTOMER_SK 78 +#define CS_BILL_CDEMO_SK 79 +#define CS_BILL_HDEMO_SK 80 +#define CS_BILL_ADDR_SK 81 +#define CS_SHIP_CUSTOMER_SK 82 +#define CS_SHIP_CDEMO_SK 83 +#define CS_SHIP_HDEMO_SK 84 +#define CS_SHIP_ADDR_SK 85 +#define CS_CALL_CENTER_SK 86 +#define CS_CATALOG_PAGE_SK 87 +#define CS_SHIP_MODE_SK 88 +#define CS_WAREHOUSE_SK 89 +#define CS_SOLD_ITEM_SK 90 +#define CS_PROMO_SK 91 +#define CS_ORDER_NUMBER 92 +#define CS_PRICING_QUANTITY 93 +#define CS_PRICING_WHOLESALE_COST 94 +#define CS_PRICING_LIST_PRICE 95 +#define CS_PRICING_SALES_PRICE 96 +#define CS_PRICING_COUPON_AMT 97 +#define CS_PRICING_EXT_SALES_PRICE 98 +#define CS_PRICING_EXT_DISCOUNT_AMOUNT 99 +#define CS_PRICING_EXT_WHOLESALE_COST 100 +#define CS_PRICING_EXT_LIST_PRICE 101 +#define CS_PRICING_EXT_TAX 102 +#define CS_PRICING_EXT_SHIP_COST 103 +#define CS_PRICING_NET_PAID 104 +#define CS_PRICING_NET_PAID_INC_TAX 105 +#define CS_PRICING_NET_PAID_INC_SHIP 106 +#define CS_PRICING_NET_PAID_INC_SHIP_TAX 107 +#define CS_PRICING_NET_PROFIT 108 +#define CS_PRICING 109 +#define CS_PERMUTE 110 +#define CS_NULLS 111 +#define CR_IS_RETURNED 112 +#define CS_PERMUTATION 113 +#define CATALOG_SALES_END 113 +#define CUSTOMER_START 114 +#define C_CUSTOMER_SK 114 +#define C_CUSTOMER_ID 115 +#define C_CURRENT_CDEMO_SK 116 +#define C_CURRENT_HDEMO_SK 117 +#define C_CURRENT_ADDR_SK 118 +#define C_FIRST_SHIPTO_DATE_ID 119 +#define C_FIRST_SALES_DATE_ID 120 +#define C_SALUTATION 121 +#define C_FIRST_NAME 122 +#define C_LAST_NAME 123 +#define C_PREFERRED_CUST_FLAG 124 +#define C_BIRTH_DAY 125 +#define C_BIRTH_MONTH 126 +#define C_BIRTH_YEAR 127 +#define C_BIRTH_COUNTRY 128 +#define C_LOGIN 129 +#define C_EMAIL_ADDRESS 130 +#define C_LAST_REVIEW_DATE 131 +#define C_NULLS 132 +#define CUSTOMER_END 132 +#define CUSTOMER_ADDRESS_START 133 +#define CA_ADDRESS_SK 133 +#define CA_ADDRESS_ID 134 +#define CA_ADDRESS_STREET_NUM 135 +#define CA_ADDRESS_STREET_NAME1 136 +#define CA_ADDRESS_STREET_TYPE 137 +#define CA_ADDRESS_SUITE_NUM 138 +#define CA_ADDRESS_CITY 139 +#define CA_ADDRESS_COUNTY 140 +#define CA_ADDRESS_STATE 141 +#define CA_ADDRESS_ZIP 142 +#define CA_ADDRESS_COUNTRY 143 +#define CA_ADDRESS_GMT_OFFSET 144 +#define CA_LOCATION_TYPE 145 +#define CA_NULLS 146 +#define CA_ADDRESS 147 +#define CA_ADDRESS_STREET_NAME2 148 +#define CUSTOMER_ADDRESS_END 148 +#define CUSTOMER_DEMOGRAPHICS_START 149 +#define CD_DEMO_SK 149 +#define CD_GENDER 150 +#define CD_MARITAL_STATUS 151 +#define CD_EDUCATION_STATUS 152 +#define CD_PURCHASE_ESTIMATE 153 +#define CD_CREDIT_RATING 154 +#define CD_DEP_COUNT 155 +#define CD_DEP_EMPLOYED_COUNT 156 +#define CD_DEP_COLLEGE_COUNT 157 +#define CD_NULLS 158 +#define CUSTOMER_DEMOGRAPHICS_END 158 +#define DATE_START 159 +#define D_DATE_SK 159 +#define D_DATE_ID 160 +#define D_DATE 161 +#define D_MONTH_SEQ 162 +#define D_WEEK_SEQ 163 +#define D_QUARTER_SEQ 164 +#define D_YEAR 165 +#define D_DOW 166 +#define D_MOY 167 +#define D_DOM 168 +#define D_QOY 169 +#define D_FY_YEAR 170 +#define D_FY_QUARTER_SEQ 171 +#define D_FY_WEEK_SEQ 172 +#define D_DAY_NAME 173 +#define D_QUARTER_NAME 174 +#define D_HOLIDAY 175 +#define D_WEEKEND 176 +#define D_FOLLOWING_HOLIDAY 177 +#define D_FIRST_DOM 178 +#define D_LAST_DOM 179 +#define D_SAME_DAY_LY 180 +#define D_SAME_DAY_LQ 181 +#define D_CURRENT_DAY 182 +#define D_CURRENT_WEEK 183 +#define D_CURRENT_MONTH 184 +#define D_CURRENT_QUARTER 185 +#define D_CURRENT_YEAR 186 +#define D_NULLS 187 +#define DATE_END 187 +#define HOUSEHOLD_DEMOGRAPHICS_START 188 +#define HD_DEMO_SK 188 +#define HD_INCOME_BAND_ID 189 +#define HD_BUY_POTENTIAL 190 +#define HD_DEP_COUNT 191 +#define HD_VEHICLE_COUNT 192 +#define HD_NULLS 193 +#define HOUSEHOLD_DEMOGRAPHICS_END 193 +#define INCOME_BAND_START 194 +#define IB_INCOME_BAND_ID 194 +#define IB_LOWER_BOUND 195 +#define IB_UPPER_BOUND 196 +#define IB_NULLS 197 +#define INCOME_BAND_END 197 +#define INVENTORY_START 198 +#define INV_DATE_SK 198 +#define INV_ITEM_SK 199 +#define INV_WAREHOUSE_SK 200 +#define INV_QUANTITY_ON_HAND 201 +#define INV_NULLS 202 +#define INVENTORY_END 202 +#define ITEM_START 203 +#define I_ITEM_SK 203 +#define I_ITEM_ID 204 +#define I_REC_START_DATE_ID 205 +#define I_REC_END_DATE_ID 206 +#define I_ITEM_DESC 207 +#define I_CURRENT_PRICE 208 +#define I_WHOLESALE_COST 209 +#define I_BRAND_ID 210 +#define I_BRAND 211 +#define I_CLASS_ID 212 +#define I_CLASS 213 +#define I_CATEGORY_ID 214 +#define I_CATEGORY 215 +#define I_MANUFACT_ID 216 +#define I_MANUFACT 217 +#define I_SIZE 218 +#define I_FORMULATION 219 +#define I_COLOR 220 +#define I_UNITS 221 +#define I_CONTAINER 222 +#define I_MANAGER_ID 223 +#define I_PRODUCT_NAME 224 +#define I_NULLS 225 +#define I_SCD 226 +#define I_PROMO_SK 227 +#define ITEM_END 227 +#define PROMOTION_START 228 +#define P_PROMO_SK 228 +#define P_PROMO_ID 229 +#define P_START_DATE_ID 230 +#define P_END_DATE_ID 231 +#define P_ITEM_SK 232 +#define P_COST 233 +#define P_RESPONSE_TARGET 234 +#define P_PROMO_NAME 235 +#define P_CHANNEL_DMAIL 236 +#define P_CHANNEL_EMAIL 237 +#define P_CHANNEL_CATALOG 238 +#define P_CHANNEL_TV 239 +#define P_CHANNEL_RADIO 240 +#define P_CHANNEL_PRESS 241 +#define P_CHANNEL_EVENT 242 +#define P_CHANNEL_DEMO 243 +#define P_CHANNEL_DETAILS 244 +#define P_PURPOSE 245 +#define P_DISCOUNT_ACTIVE 246 +#define P_NULLS 247 +#define PROMOTION_END 247 +#define REASON_START 248 +#define R_REASON_SK 248 +#define R_REASON_ID 249 +#define R_REASON_DESCRIPTION 250 +#define R_NULLS 251 +#define REASON_END 251 +#define SHIP_MODE_START 252 +#define SM_SHIP_MODE_SK 252 +#define SM_SHIP_MODE_ID 253 +#define SM_TYPE 254 +#define SM_CODE 255 +#define SM_CONTRACT 256 +#define SM_CARRIER 257 +#define SM_NULLS 258 +#define SHIP_MODE_END 258 +#define STORE_START 259 +#define W_STORE_SK 259 +#define W_STORE_ID 260 +#define W_STORE_REC_START_DATE_ID 261 +#define W_STORE_REC_END_DATE_ID 262 +#define W_STORE_CLOSED_DATE_ID 263 +#define W_STORE_NAME 264 +#define W_STORE_EMPLOYEES 265 +#define W_STORE_FLOOR_SPACE 266 +#define W_STORE_HOURS 267 +#define W_STORE_MANAGER 268 +#define W_STORE_MARKET_ID 269 +#define W_STORE_TAX_PERCENTAGE 270 +#define W_STORE_GEOGRAPHY_CLASS 271 +#define W_STORE_MARKET_DESC 272 +#define W_STORE_MARKET_MANAGER 273 +#define W_STORE_DIVISION_ID 274 +#define W_STORE_DIVISION_NAME 275 +#define W_STORE_COMPANY_ID 276 +#define W_STORE_COMPANY_NAME 277 +#define W_STORE_ADDRESS_STREET_NUM 278 +#define W_STORE_ADDRESS_STREET_NAME1 279 +#define W_STORE_ADDRESS_STREET_TYPE 280 +#define W_STORE_ADDRESS_SUITE_NUM 281 +#define W_STORE_ADDRESS_CITY 282 +#define W_STORE_ADDRESS_COUNTY 283 +#define W_STORE_ADDRESS_STATE 284 +#define W_STORE_ADDRESS_ZIP 285 +#define W_STORE_ADDRESS_COUNTRY 286 +#define W_STORE_ADDRESS_GMT_OFFSET 287 +#define W_STORE_NULLS 288 +#define W_STORE_TYPE 289 +#define W_STORE_SCD 290 +#define W_STORE_ADDRESS 291 +#define STORE_END 291 +#define STORE_RETURNS_START 292 +#define SR_RETURNED_DATE_SK 292 +#define SR_RETURNED_TIME_SK 293 +#define SR_ITEM_SK 294 +#define SR_CUSTOMER_SK 295 +#define SR_CDEMO_SK 296 +#define SR_HDEMO_SK 297 +#define SR_ADDR_SK 298 +#define SR_STORE_SK 299 +#define SR_REASON_SK 300 +#define SR_TICKET_NUMBER 301 +#define SR_PRICING_QUANTITY 302 +#define SR_PRICING_NET_PAID 303 +#define SR_PRICING_EXT_TAX 304 +#define SR_PRICING_NET_PAID_INC_TAX 305 +#define SR_PRICING_FEE 306 +#define SR_PRICING_EXT_SHIP_COST 307 +#define SR_PRICING_REFUNDED_CASH 308 +#define SR_PRICING_REVERSED_CHARGE 309 +#define SR_PRICING_STORE_CREDIT 310 +#define SR_PRICING_NET_LOSS 311 +#define SR_PRICING 312 +#define SR_NULLS 313 +#define STORE_RETURNS_END 313 +#define STORE_SALES_START 314 +#define SS_SOLD_DATE_SK 314 +#define SS_SOLD_TIME_SK 315 +#define SS_SOLD_ITEM_SK 316 +#define SS_SOLD_CUSTOMER_SK 317 +#define SS_SOLD_CDEMO_SK 318 +#define SS_SOLD_HDEMO_SK 319 +#define SS_SOLD_ADDR_SK 320 +#define SS_SOLD_STORE_SK 321 +#define SS_SOLD_PROMO_SK 322 +#define SS_TICKET_NUMBER 323 +#define SS_PRICING_QUANTITY 324 +#define SS_PRICING_WHOLESALE_COST 325 +#define SS_PRICING_LIST_PRICE 326 +#define SS_PRICING_SALES_PRICE 327 +#define SS_PRICING_COUPON_AMT 328 +#define SS_PRICING_EXT_SALES_PRICE 329 +#define SS_PRICING_EXT_WHOLESALE_COST 330 +#define SS_PRICING_EXT_LIST_PRICE 331 +#define SS_PRICING_EXT_TAX 332 +#define SS_PRICING_NET_PAID 333 +#define SS_PRICING_NET_PAID_INC_TAX 334 +#define SS_PRICING_NET_PROFIT 335 +#define SR_IS_RETURNED 336 +#define SS_PRICING 337 +#define SS_NULLS 338 +#define SS_PERMUTATION 339 +#define STORE_SALES_END 339 +#define TIME_START 340 +#define T_TIME_SK 340 +#define T_TIME_ID 341 +#define T_TIME 342 +#define T_HOUR 343 +#define T_MINUTE 344 +#define T_SECOND 345 +#define T_AM_PM 346 +#define T_SHIFT 347 +#define T_SUB_SHIFT 348 +#define T_MEAL_TIME 349 +#define T_NULLS 350 +#define TIME_END 350 +#define WAREHOUSE_START 351 +#define W_WAREHOUSE_SK 351 +#define W_WAREHOUSE_ID 352 +#define W_WAREHOUSE_NAME 353 +#define W_WAREHOUSE_SQ_FT 354 +#define W_ADDRESS_STREET_NUM 355 +#define W_ADDRESS_STREET_NAME1 356 +#define W_ADDRESS_STREET_TYPE 357 +#define W_ADDRESS_SUITE_NUM 358 +#define W_ADDRESS_CITY 359 +#define W_ADDRESS_COUNTY 360 +#define W_ADDRESS_STATE 361 +#define W_ADDRESS_ZIP 362 +#define W_ADDRESS_COUNTRY 363 +#define W_ADDRESS_GMT_OFFSET 364 +#define W_NULLS 365 +#define W_WAREHOUSE_ADDRESS 366 +#define WAREHOUSE_END 366 +#define WEB_PAGE_START 367 +#define WP_PAGE_SK 367 +#define WP_PAGE_ID 368 +#define WP_REC_START_DATE_ID 369 +#define WP_REC_END_DATE_ID 370 +#define WP_CREATION_DATE_SK 371 +#define WP_ACCESS_DATE_SK 372 +#define WP_AUTOGEN_FLAG 373 +#define WP_CUSTOMER_SK 374 +#define WP_URL 375 +#define WP_TYPE 376 +#define WP_CHAR_COUNT 377 +#define WP_LINK_COUNT 378 +#define WP_IMAGE_COUNT 379 +#define WP_MAX_AD_COUNT 380 +#define WP_NULLS 381 +#define WP_SCD 382 +#define WEB_PAGE_END 382 +#define WEB_RETURNS_START 383 +#define WR_RETURNED_DATE_SK 383 +#define WR_RETURNED_TIME_SK 384 +#define WR_ITEM_SK 385 +#define WR_REFUNDED_CUSTOMER_SK 386 +#define WR_REFUNDED_CDEMO_SK 387 +#define WR_REFUNDED_HDEMO_SK 388 +#define WR_REFUNDED_ADDR_SK 389 +#define WR_RETURNING_CUSTOMER_SK 390 +#define WR_RETURNING_CDEMO_SK 391 +#define WR_RETURNING_HDEMO_SK 392 +#define WR_RETURNING_ADDR_SK 393 +#define WR_WEB_PAGE_SK 394 +#define WR_REASON_SK 395 +#define WR_ORDER_NUMBER 396 +#define WR_PRICING_QUANTITY 397 +#define WR_PRICING_NET_PAID 398 +#define WR_PRICING_EXT_TAX 399 +#define WR_PRICING_NET_PAID_INC_TAX 400 +#define WR_PRICING_FEE 401 +#define WR_PRICING_EXT_SHIP_COST 402 +#define WR_PRICING_REFUNDED_CASH 403 +#define WR_PRICING_REVERSED_CHARGE 404 +#define WR_PRICING_STORE_CREDIT 405 +#define WR_PRICING_NET_LOSS 406 +#define WR_PRICING 407 +#define WR_NULLS 408 +#define WEB_RETURNS_END 408 +#define WEB_SALES_START 409 +#define WS_SOLD_DATE_SK 409 +#define WS_SOLD_TIME_SK 410 +#define WS_SHIP_DATE_SK 411 +#define WS_ITEM_SK 412 +#define WS_BILL_CUSTOMER_SK 413 +#define WS_BILL_CDEMO_SK 414 +#define WS_BILL_HDEMO_SK 415 +#define WS_BILL_ADDR_SK 416 +#define WS_SHIP_CUSTOMER_SK 417 +#define WS_SHIP_CDEMO_SK 418 +#define WS_SHIP_HDEMO_SK 419 +#define WS_SHIP_ADDR_SK 420 +#define WS_WEB_PAGE_SK 421 +#define WS_WEB_SITE_SK 422 +#define WS_SHIP_MODE_SK 423 +#define WS_WAREHOUSE_SK 424 +#define WS_PROMO_SK 425 +#define WS_ORDER_NUMBER 426 +#define WS_PRICING_QUANTITY 427 +#define WS_PRICING_WHOLESALE_COST 428 +#define WS_PRICING_LIST_PRICE 429 +#define WS_PRICING_SALES_PRICE 430 +#define WS_PRICING_EXT_DISCOUNT_AMT 431 +#define WS_PRICING_EXT_SALES_PRICE 432 +#define WS_PRICING_EXT_WHOLESALE_COST 433 +#define WS_PRICING_EXT_LIST_PRICE 434 +#define WS_PRICING_EXT_TAX 435 +#define WS_PRICING_COUPON_AMT 436 +#define WS_PRICING_EXT_SHIP_COST 437 +#define WS_PRICING_NET_PAID 438 +#define WS_PRICING_NET_PAID_INC_TAX 439 +#define WS_PRICING_NET_PAID_INC_SHIP 440 +#define WS_PRICING_NET_PAID_INC_SHIP_TAX 441 +#define WS_PRICING_NET_PROFIT 442 +#define WS_PRICING 443 +#define WS_NULLS 444 +#define WR_IS_RETURNED 445 +#define WS_PERMUTATION 446 +#define WEB_SALES_END 446 +#define WEB_SITE_START 447 +#define WEB_SITE_SK 447 +#define WEB_SITE_ID 448 +#define WEB_REC_START_DATE_ID 449 +#define WEB_REC_END_DATE_ID 450 +#define WEB_NAME 451 +#define WEB_OPEN_DATE 452 +#define WEB_CLOSE_DATE 453 +#define WEB_CLASS 454 +#define WEB_MANAGER 455 +#define WEB_MARKET_ID 456 +#define WEB_MARKET_CLASS 457 +#define WEB_MARKET_DESC 458 +#define WEB_MARKET_MANAGER 459 +#define WEB_COMPANY_ID 460 +#define WEB_COMPANY_NAME 461 +#define WEB_ADDRESS_STREET_NUM 462 +#define WEB_ADDRESS_STREET_NAME1 463 +#define WEB_ADDRESS_STREET_TYPE 464 +#define WEB_ADDRESS_SUITE_NUM 465 +#define WEB_ADDRESS_CITY 466 +#define WEB_ADDRESS_COUNTY 467 +#define WEB_ADDRESS_STATE 468 +#define WEB_ADDRESS_ZIP 469 +#define WEB_ADDRESS_COUNTRY 470 +#define WEB_ADDRESS_GMT_OFFSET 471 +#define WEB_TAX_PERCENTAGE 472 +#define WEB_NULLS 473 +#define WEB_ADDRESS 474 +#define WEB_SCD 475 +#define WEB_SITE_END 475 +#define DBGEN_VERSION_START 476 +#define DV_VERSION 476 +#define DV_CREATE_DATE 477 +#define DV_CREATE_TIME 478 +#define DV_CMDLINE_ARGS 479 +#define VALIDATE_STREAM 480 +#define DBGEN_VERSION_END 480 +#define S_BRAND_START 481 +#define S_BRAND_ID 481 +#define S_BRAND_SUBCLASS_ID 482 +#define S_BRAND_MANAGER_ID 483 +#define S_BRAND_MANUFACTURER_ID 484 +#define S_BRAND_NAME 485 +#define S_BRAND_END 485 +#define S_CUSTOMER_ADDRESS_START 486 +#define S_CADR_ID 486 +#define S_CADR_ADDRESS_STREET_NUMBER 487 +#define S_CADR_ADDRESS_STREET_NAME1 488 +#define S_CADR_ADDRESS_STREET_NAME2 489 +#define S_CADR_ADDRESS_STREET_TYPE 490 +#define S_CADR_ADDRESS_SUITE_NUM 491 +#define S_CADR_ADDRESS_CITY 492 +#define S_CADR_ADDRESS_COUNTY 493 +#define S_CADR_ADDRESS_STATE 494 +#define S_CADR_ADDRESS_ZIP 495 +#define S_CADR_ADDRESS_COUNTRY 496 +#define S_BADDR_ADDRESS 497 +#define S_CUSTOMER_ADDRESS_END 497 +#define S_CALL_CENTER_START 498 +#define S_CALL_CENTER_ID 498 +#define S_CALL_CENTER_DIVISION_ID 499 +#define S_CALL_CENTER_OPEN_DATE 500 +#define S_CALL_CENTER_CLOSED_DATE 501 +#define S_CALL_CENTER_NAME 502 +#define S_CALL_CENTER_CLASS 503 +#define S_CALL_CENTER_EMPLOYEES 504 +#define S_CALL_CENTER_SQFT 505 +#define S_CALL_CENTER_HOURS 506 +#define S_CALL_CENTER_MANAGER_ID 507 +#define S_CALL_CENTER_MARKET_ID 508 +#define S_CALL_CENTER_ADDRESS_ID 509 +#define S_CALL_CENTER_TAX_PERCENTAGE 510 +#define S_CALL_CENTER_SCD 511 +#define S_CALL_CENTER_END 511 +#define S_CATALOG_START 512 +#define S_CATALOG_NUMBER 512 +#define S_CATALOG_START_DATE 513 +#define S_CATALOG_END_DATE 514 +#define S_CATALOG_DESC 515 +#define S_CATALOG_TYPE 516 +#define S_CATALOG_END 516 +#define S_CATALOG_ORDER_START 517 +#define S_CORD_ID 517 +#define S_CORD_BILL_CUSTOMER_ID 518 +#define S_CORD_SHIP_CUSTOMER_ID 519 +#define S_CORD_ORDER_DATE 520 +#define S_CORD_ORDER_TIME 521 +#define S_CORD_SHIP_MODE_ID 522 +#define S_CORD_CALL_CENTER_ID 523 +#define S_CLIN_ITEM_ID 524 +#define S_CORD_COMMENT 525 +#define S_CATALOG_ORDER_END 525 +#define S_CATALOG_ORDER_LINEITEM_START 526 +#define S_CLIN_ORDER_ID 526 +#define S_CLIN_LINE_NUMBER 527 +#define S_CLIN_PROMOTION_ID 528 +#define S_CLIN_QUANTITY 529 +#define S_CLIN_COUPON_AMT 530 +#define S_CLIN_WAREHOUSE_ID 531 +#define S_CLIN_SHIP_DATE 532 +#define S_CLIN_CATALOG_ID 533 +#define S_CLIN_CATALOG_PAGE_ID 534 +#define S_CLIN_PRICING 535 +#define S_CLIN_SHIP_COST 536 +#define S_CLIN_IS_RETURNED 537 +#define S_CLIN_PERMUTE 538 +#define S_CATALOG_ORDER_LINEITEM_END 538 +#define S_CATALOG_PAGE_START 539 +#define S_CATALOG_PAGE_CATALOG_NUMBER 539 +#define S_CATALOG_PAGE_NUMBER 540 +#define S_CATALOG_PAGE_DEPARTMENT 541 +#define S_CP_ID 542 +#define S_CP_START_DATE 543 +#define S_CP_END_DATE 544 +#define S_CP_DESCRIPTION 545 +#define S_CP_TYPE 546 +#define S_CATALOG_PAGE_END 546 +#define S_CATALOG_PROMOTIONAL_ITEM_START 547 +#define S_CATALOG_PROMOTIONAL_ITEM_CATALOG_NUMBER 547 +#define S_CATALOG_PROMOTIONAL_ITEM_CATALOG_PAGE_NUMBER 548 +#define S_CATALOG_PROMOTIONAL_ITEM_ITEM_ID 549 +#define S_CATALOG_PROMOTIONAL_ITEM_PROMOTION_ID 550 +#define S_CATALOG_PROMOTIONAL_ITEM_END 550 +#define S_CATALOG_RETURNS_START 551 +#define S_CRET_CALL_CENTER_ID 551 +#define S_CRET_ORDER_ID 552 +#define S_CRET_LINE_NUMBER 553 +#define S_CRET_ITEM_ID 554 +#define S_CRET_RETURN_CUSTOMER_ID 555 +#define S_CRET_REFUND_CUSTOMER_ID 556 +#define S_CRET_DATE 557 +#define S_CRET_TIME 558 +#define S_CRET_QUANTITY 559 +#define S_CRET_AMOUNT 560 +#define S_CRET_TAX 561 +#define S_CRET_FEE 562 +#define S_CRET_SHIP_COST 563 +#define S_CRET_REFUNDED_CASH 564 +#define S_CRET_REVERSED_CHARGE 565 +#define S_CRET_MERCHANT_CREDIT 566 +#define S_CRET_REASON_ID 567 +#define S_CRET_PRICING 568 +#define S_CRET_SHIPMODE_ID 569 +#define S_CRET_WAREHOUSE_ID 570 +#define S_CRET_CATALOG_PAGE_ID 571 +#define S_CATALOG_RETURNS_END 571 +#define S_CATEGORY_START 572 +#define S_CATEGORY_ID 572 +#define S_CATEGORY_NAME 573 +#define S_CATEGORY_DESC 574 +#define S_CATEGORY_END 574 +#define S_CLASS_START 575 +#define S_CLASS_ID 575 +#define S_CLASS_SUBCAT_ID 576 +#define S_CLASS_DESC 577 +#define S_CLASS_END 577 +#define S_COMPANY_START 578 +#define S_COMPANY_ID 578 +#define S_COMPANY_NAME 579 +#define S_COMPANY_END 579 +#define S_CUSTOMER_START 580 +#define S_CUST_ID 580 +#define S_CUST_SALUTATION 581 +#define S_CUST_LAST_NAME 582 +#define S_CUST_FIRST_NAME 583 +#define S_CUST_PREFERRED_FLAG 584 +#define S_CUST_BIRTH_DATE 585 +#define S_CUST_FIRST_PURCHASE_DATE 586 +#define S_CUST_FIRST_SHIPTO_DATE 587 +#define S_CUST_BIRTH_COUNTRY 588 +#define S_CUST_LOGIN 589 +#define S_CUST_EMAIL 590 +#define S_CUST_LAST_LOGIN 591 +#define S_CUST_LAST_REVIEW 592 +#define S_CUST_PRIMARY_MACHINE 593 +#define S_CUST_SECONDARY_MACHINE 594 +#define S_CUST_ADDRESS 595 +#define S_CUST_ADDRESS_STREET_NUM 596 +#define S_CUST_ADDRESS_STREET_NAME1 597 +#define S_CUST_ADDRESS_STREET_NAME2 598 +#define S_CUST_ADDRESS_STREET_TYPE 599 +#define S_CUST_ADDRESS_SUITE_NUM 600 +#define S_CUST_ADDRESS_CITY 601 +#define S_CUST_ADDRESS_ZIP 602 +#define S_CUST_ADDRESS_COUNTY 603 +#define S_CUST_ADDRESS_STATE 604 +#define S_CUST_ADDRESS_COUNTRY 605 +#define S_CUST_LOCATION_TYPE 606 +#define S_CUST_GENDER 607 +#define S_CUST_MARITAL_STATUS 608 +#define S_CUST_EDUCATION 609 +#define S_CUST_CREDIT_RATING 610 +#define S_CUST_PURCHASE_ESTIMATE 611 +#define S_CUST_BUY_POTENTIAL 612 +#define S_CUST_DEPENDENT_CNT 613 +#define S_CUST_EMPLOYED_CNT 614 +#define S_CUST_COLLEGE_CNT 615 +#define S_CUST_VEHICLE_CNT 616 +#define S_CUST_INCOME 617 +#define S_CUSTOMER_END 617 +#define S_DIVISION_START 618 +#define S_DIVISION_ID 618 +#define S_DIVISION_COMPANY 619 +#define S_DIVISION_NAME 620 +#define S_DIVISION_END 620 +#define S_INVENTORY_START 621 +#define S_INVN_WAREHOUSE 621 +#define S_INVN_ITEM 622 +#define S_INVN_DATE 623 +#define S_INVN_QUANTITY 624 +#define S_INVENTORY_END 624 +#define S_ITEM_START 625 +#define S_ITEM_ID 625 +#define S_ITEM_PERMUTE 626 +#define S_ITEM_PRODUCT_ID 627 +#define S_ITEM_DESC 628 +#define S_ITEM_LIST_PRICE 629 +#define S_ITEM_WHOLESALE_COST 630 +#define S_ITEM_MANAGER_ID 631 +#define S_ITEM_SIZE 632 +#define S_ITEM_FORMULATION 633 +#define S_ITEM_FLAVOR 634 +#define S_ITEM_UNITS 635 +#define S_ITEM_CONTAINER 636 +#define S_ITEM_SCD 637 +#define S_ITEM_END 637 +#define S_MANAGER_START 638 +#define S_MANAGER_ID 638 +#define S_MANAGER_NAME 639 +#define S_MANAGER_END 639 +#define S_MANUFACTURER_START 640 +#define S_MANUFACTURER_ID 640 +#define S_MANUFACTURER_NAME 641 +#define S_MANUFACTURER_END 641 +#define S_MARKET_START 642 +#define S_MARKET_ID 642 +#define S_MARKET_CLASS_NAME 643 +#define S_MARKET_DESC 644 +#define S_MARKET_MANAGER_ID 645 +#define S_MARKET_END 645 +#define S_PRODUCT_START 646 +#define S_PRODUCT_ID 646 +#define S_PRODUCT_BRAND_ID 647 +#define S_PRODUCT_NAME 648 +#define S_PRODUCT_TYPE 649 +#define S_PRODUCT_END 649 +#define S_PROMOTION_START 650 +#define S_PROMOTION_ID 650 +#define S_PROMOTION_ITEM_ID 651 +#define S_PROMOTION_START_DATE 652 +#define S_PROMOTION_END_DATE 653 +#define S_PROMOTION_COST 654 +#define S_PROMOTION_RESPONSE_TARGET 655 +#define S_PROMOTION_DMAIL 656 +#define S_PROMOTION_EMAIL 657 +#define S_PROMOTION_CATALOG 658 +#define S_PROMOTION_TV 659 +#define S_PROMOTION_RADIO 660 +#define S_PROMOTION_PRESS 661 +#define S_PROMOTION_EVENT 662 +#define S_PROMOTION_DEMO 663 +#define S_PROMOTION_DETAILS 664 +#define S_PROMOTION_PURPOSE 665 +#define S_PROMOTION_DISCOUNT_ACTIVE 666 +#define S_PROMOTION_DISCOUNT_PCT 667 +#define S_PROMOTION_NAME 668 +#define S_PROMOTION_BITFIELD 669 +#define S_PROMOTION_END 669 +#define S_PURCHASE_START 670 +#define S_PURCHASE_ID 670 +#define S_PURCHASE_STORE_ID 671 +#define S_PURCHASE_CUSTOMER_ID 672 +#define S_PURCHASE_DATE 673 +#define S_PURCHASE_TIME 674 +#define S_PURCHASE_REGISTER 675 +#define S_PURCHASE_CLERK 676 +#define S_PURCHASE_COMMENT 677 +#define S_PURCHASE_PRICING 678 +#define S_PLINE_ITEM_ID 679 +#define S_PURCHASE_END 679 +#define S_PURCHASE_LINEITEM_START 680 +#define S_PLINE_PURCHASE_ID 680 +#define S_PLINE_NUMBER 681 +#define S_PLINE_PROMOTION_ID 682 +#define S_PLINE_SALE_PRICE 683 +#define S_PLINE_QUANTITY 684 +#define S_PLINE_COUPON_AMT 685 +#define S_PLINE_COMMENT 686 +#define S_PLINE_PRICING 687 +#define S_PLINE_IS_RETURNED 688 +#define S_PLINE_PERMUTE 689 +#define S_PURCHASE_LINEITEM_END 689 +#define S_REASON_START 690 +#define S_REASON_ID 690 +#define S_REASON_DESC 691 +#define S_REASON_END 691 +#define S_STORE_START 692 +#define S_STORE_ID 692 +#define S_STORE_ADDRESS_ID 693 +#define S_STORE_DIVISION_ID 694 +#define S_STORE_OPEN_DATE 695 +#define S_STORE_CLOSE_DATE 696 +#define S_STORE_NAME 697 +#define S_STORE_CLASS 698 +#define S_STORE_EMPLOYEES 699 +#define S_STORE_FLOOR_SPACE 700 +#define S_STORE_HOURS 701 +#define S_STORE_MARKET_MANAGER_ID 702 +#define S_STORE_MANAGER_ID 703 +#define S_STORE_MARKET_ID 704 +#define S_STORE_GEOGRAPHY_CLASS 705 +#define S_STORE_TAX_PERCENTAGE 706 +#define S_STORE_END 706 +#define S_STORE_PROMOTIONAL_ITEM_START 707 +#define S_SITM_PROMOTION_ID 707 +#define S_SITM_ITEM_ID 708 +#define S_SITM_STORE_ID 709 +#define S_STORE_PROMOTIONAL_ITEM_END 709 +#define S_STORE_RETURNS_START 710 +#define S_SRET_STORE_ID 710 +#define S_SRET_PURCHASE_ID 711 +#define S_SRET_LINENUMBER 712 +#define S_SRET_ITEM_ID 713 +#define S_SRET_CUSTOMER_ID 714 +#define S_SRET_RETURN_DATE 715 +#define S_SRET_RETURN_TIME 716 +#define S_SRET_TICKET_NUMBER 717 +#define S_SRET_RETURN_QUANTITY 718 +#define S_SRET_RETURN_AMT 719 +#define S_SRET_RETURN_TAX 720 +#define S_SRET_RETURN_FEE 721 +#define S_SRET_RETURN_SHIP_COST 722 +#define S_SRET_REFUNDED_CASH 723 +#define S_SRET_REVERSED_CHARGE 724 +#define S_SRET_MERCHANT_CREDIT 725 +#define S_SRET_REASON_ID 726 +#define S_SRET_PRICING 727 +#define S_STORE_RETURNS_END 727 +#define S_SUBCATEGORY_START 728 +#define S_SBCT_ID 728 +#define S_SBCT_CATEGORY_ID 729 +#define S_SBCT_NAME 730 +#define S_SBCT_DESC 731 +#define S_SUBCATEGORY_END 731 +#define S_SUBCLASS_START 732 +#define S_SUBC_ID 732 +#define S_SUBC_CLASS_ID 733 +#define S_SUBC_NAME 734 +#define S_SUBC_DESC 735 +#define S_SUBCLASS_END 735 +#define S_WAREHOUSE_START 736 +#define S_WRHS_ID 736 +#define S_WRHS_DESC 737 +#define S_WRHS_SQFT 738 +#define S_WRHS_ADDRESS_ID 739 +#define S_WAREHOUSE_END 739 +#define S_WEB_ORDER_START 740 +#define S_WORD_ID 740 +#define S_WORD_BILL_CUSTOMER_ID 741 +#define S_WORD_SHIP_CUSTOMER_ID 742 +#define S_WORD_ORDER_DATE 743 +#define S_WORD_ORDER_TIME 744 +#define S_WORD_SHIP_MODE_ID 745 +#define S_WORD_WEB_SITE_ID 746 +#define S_WORD_COMMENT 747 +#define S_WLIN_ITEM_ID 748 +#define S_WEB_ORDER_END 748 +#define S_WEB_ORDER_LINEITEM_START 749 +#define S_WLIN_ID 749 +#define S_WLIN_LINE_NUMBER 750 +#define S_WLIN_PROMOTION_ID 751 +#define S_WLIN_QUANTITY 752 +#define S_WLIN_COUPON_AMT 753 +#define S_WLIN_WAREHOUSE_ID 754 +#define S_WLIN_SHIP_DATE 755 +#define S_WLIN_WEB_PAGE_ID 756 +#define S_WLIN_PRICING 757 +#define S_WLIN_SHIP_COST 758 +#define S_WLIN_IS_RETURNED 759 +#define S_WLIN_PERMUTE 760 +#define S_WEB_ORDER_LINEITEM_END 760 +#define S_WEB_PAGE_START 761 +#define S_WPAG_SITE_ID 761 +#define S_WPAG_ID 762 +#define S_WPAG_CREATE_DATE 763 +#define S_WPAG_ACCESS_DATE 764 +#define S_WPAG_AUTOGEN_FLAG 765 +#define S_WPAG_DEPARTMENT 766 +#define S_WPAG_URL 767 +#define S_WPAG_TYPE 768 +#define S_WPAG_CHAR_CNT 769 +#define S_WPAG_LINK_CNT 770 +#define S_WPAG_IMAGE_CNT 771 +#define S_WPAG_MAX_AD_CNT 772 +#define S_WPAG_PERMUTE 773 +#define S_WEB_PAGE_END 773 +#define S_WEB_PROMOTIONAL_ITEM_START 774 +#define S_WITM_SITE_ID 774 +#define S_WITM_PAGE_ID 775 +#define S_WITM_ITEM_ID 776 +#define S_WITM_PROMOTION_ID 777 +#define S_WEB_PROMOTIONAL_ITEM_END 777 +#define S_WEB_RETURNS_START 778 +#define S_WRET_SITE_ID 778 +#define S_WRET_ORDER_ID 779 +#define S_WRET_LINE_NUMBER 780 +#define S_WRET_ITEM_ID 781 +#define S_WRET_RETURN_CUST_ID 782 +#define S_WRET_REFUND_CUST_ID 783 +#define S_WRET_RETURN_DATE 784 +#define S_WRET_RETURN_TIME 785 +#define S_WRET_REASON_ID 786 +#define S_WRET_PRICING 787 +#define S_WEB_RETURNS_END 787 +#define S_WEB_SITE_START 788 +#define S_WSIT_ID 788 +#define S_WSIT_OPEN_DATE 789 +#define S_WSIT_CLOSE_DATE 790 +#define S_WSIT_NAME 791 +#define S_WSIT_ADDRESS_ID 792 +#define S_WSIT_DIVISION_ID 793 +#define S_WSIT_CLASS 794 +#define S_WSIT_MANAGER_ID 795 +#define S_WSIT_MARKET_ID 796 +#define S_WSIT_TAX_PERCENTAGE 797 +#define S_WEB_SITE_END 797 +#define S_ZIPG_START 798 +#define S_ZIPG_ZIP 798 +#define S_ZIPG_GMT 799 +#define S_ZIPG_END 799 +#define MAX_COLUMN 799 +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/config.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/config.h new file mode 100644 index 0000000000000..4c0c33fa7ef68 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/config.h @@ -0,0 +1,156 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef CONFIG_H +#define CONFIG_H + +// #ifdef MACOS +#define SUPPORT_64BITS +#define HUGE_TYPE int64_t +#define HUGE_FORMAT "%lld" +#define HUGE_COUNT 1 +#define USE_STRING_H +#define USE_STDLIB_H +#define USE_LIMITS_H +#include +#define MAXINT INT_MAX + +// #define FLEX +// #endif /* MACOS */ + +#ifdef NCR +#define STDLIB_HAS_GETOPT +#define USE_STRING_H +#define USE_VALUES_H +#ifdef SQLSERVER +#define WIN32 +#else +/* the 64 bit defines are for the Metaware compiler */ +#define SUPPORT_64BITS +#define HUGE_TYPE long long +#define HUGE_COUNT 1 +#define HUGE_FORMAT "%LLd" +#define int32_t int +#endif /* SQLSERVER or MP/RAS */ +#endif /* NCR */ + +#ifdef AIX +#define _ALL_SOURCE +#define USE_STRING_H +#define USE_LIMITS_H +/* + * if the C compiler is 3.1 or later, then uncomment the + * lines for 64 bit seed generation + */ +#define SUPPORT_64BITS +#define HUGE_TYPE long long +#define HUGE_COUNT 1 +#define HUGE_FORMAT "%lld" +#define STDLIB_HAS_GETOPT +#define USE_STDLIB_H +#define FLEX +#endif /* AIX */ + +#ifdef CYGWIN +#define USE_STRING_H +#define PATH_SEP '\\' +#define SUPPORT_64BITS +#define HUGE_TYPE __int64 +#define HUGE_COUNT 1 +#define HUGE_FORMAT "%I64d" +#endif /* WIN32 */ + +#ifdef HPUX +#define SUPPORT_64BITS +#define HUGE_TYPE long long int +#define HUGE_FORMAT "%lld" +#define HUGE_COUNT 1 +#define USE_STRING_H +#define USE_VALUES_H +#define USE_STDLIB_H +#define FLEX +#endif /* HPUX */ + +#ifdef INTERIX +#define USE_LIMITS_H +#define SUPPORT_64BITS +#define HUGE_TYPE long long int +#define HUGE_FORMAT "%lld" +#define HUGE_COUNT 1 +#endif /* INTERIX */ + +#ifdef LINUX +#define SUPPORT_64BITS +#define HUGE_TYPE int64_t +#define HUGE_FORMAT "%lld" +#define HUGE_COUNT 1 +#define USE_STRING_H +#define USE_VALUES_H +#define USE_STDLIB_H +#define FLEX +#endif /* LINUX */ + +#ifdef SOLARIS +#define SUPPORT_64BITS +#define HUGE_TYPE long long +#define HUGE_FORMAT "%lld" +#define HUGE_COUNT 1 +#define USE_STRING_H +#define USE_VALUES_H +#define USE_STDLIB_H +#endif /* SOLARIS */ + +#ifdef SOL86 +#define SUPPORT_64BITS +#define HUGE_TYPE long long +#define HUGE_FORMAT "%lld" +#define HUGE_COUNT 1 +#define USE_STRING_H +#define USE_VALUES_H +#define USE_STDLIB_H +#endif /* SOLARIS */ + +#ifdef WIN32 +#define USE_STRING_H +#define USE_LIMITS_H +#define PATH_SEP '\\' +#define SUPPORT_64BITS +#define HUGE_TYPE __int64 +#define HUGE_COUNT 1 +#define HUGE_FORMAT "%I64d" +#endif /* WIN32 */ + +/* preliminary defines for 64-bit windows compile */ +#ifdef WIN64 +#define USE_STRING_H +#define PATH_SEP '\\' +#define SUPPORT_64BITS +#define HUGE_TYPE __int64 +#define HUGE_COUNT 1 +#define HUGE_FORMAT "%I64d" +#endif /* WIN32 */ + +#ifndef PATH_SEP +#define PATH_SEP '/' +#endif /* PATH_SEP */ + +#ifndef HUGE_TYPE +#error The code now requires 64b support +#endif + +/*** + ** DATABASE DEFINES + ***/ +#ifdef _MYSQL +#define STR_QUOTES +#endif + +#endif /* CONFIG_H */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/constants.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/constants.h new file mode 100644 index 0000000000000..8fb90df1a208b --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/constants.h @@ -0,0 +1,310 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef CONSTANTS_H +#define CONSTANTS_H +/*** +*** Multi-table/Global Defines +***/ +#define DATA_START_DATE "1998-01-01" /* earliest date in the data set */ +#define DATA_END_DATE "2003-12-31" /* latest date in the data set */ +#define LINES_PER_ORDER \ + 16 /* max number of lineitems per order for all channels */ + +/*** +*** C_xxx Cutomer Defines +***/ +#define C_PREFERRED_PCT 50 + +/*** + *** CC_xxx Call Center Defines + ***/ +#define CC_EMPLOYEE_MAX 7 /* rises ~ scale ^ 2 */ + +/*** + *** CP_xxx Catalog Page Defines + ***/ +#define CP_CATALOGS_PER_YEAR 18 +#define CP_SK(c, s, p) (c * s + p) + +/*** +*** CR_xxx Catalog Returns Defines +***/ +#define CR_RETURN_PCT 10 /* percentage of catalog sales that are returned */ + +/*** +*** CS_xxx Customer Sales Defines +***/ +#define CS_QUANTITY_MAX "100" +#define CS_MARKUP_MAX "2.00" +#define CS_DISCOUNT_MAX "1.00" +#define CS_WHOLESALE_MAX "100.00" +#define CS_COUPON_MAX "0.50" +#define CS_MIN_SHIP_DELAY 2 /* minimum days from order to ship */ +#define CS_MAX_SHIP_DELAY 90 /* maximum days from order to ship */ +#define CS_ITEMS_PER_ORDER 10 /* number of items in each order */ +#define CS_GIFT_PCT 10 /* ship-to != bill-to */ + +/* + * DATE SETTINGS + * + * The benchmarks sense of "today". Should this be a sliding scale/parameter? + */ +#define CURRENT_YEAR 2003 +#define CURRENT_MONTH 1 +#define CURRENT_DAY 8 +#define CURRENT_QUARTER 1 +#define CURRENT_WEEK 2 +#define DATE_MINIMUM "1998-01-01" +#define DATE_MAXIMUM "2002-12-31" +#define YEAR_MINIMUM 1998 +#define YEAR_MAXIMUM 2002 +#define WAREHOUSE_LOAD_DATE "2001-07-18" +#define UPDATE_INTERVAL 30 /* refresh interval in days */ +#define TODAYS_DATE "2003-01-08" + +/*** + *** INV_xxx Inventory Defines + ***/ +#define INV_QUANTITY_MIN 0 +#define INV_QUANTITY_MAX 1000 + +/*** + *** ITEM_xxx Item Defines + ***/ +#define ITEM_DESC_LEN 5 +#define ITEM_NAME_LEN 10 +#define ITEM_MANFACTURER_COUNT \ + 1000 /* number of brands handled by a particular manufacturer */ + +/*** + *** PROMO_xxx Promotions Defines + ***/ +#define PROMO_NAME_LEN 5 +#define PROMO_START_MIN -720 +#define PROMO_START_MAX 100 +#define PROMO_START_MEAN 0 +#define PROMO_LEN_MIN 1 +#define PROMO_LEN_MAX 60 +#define PROMO_LEN_MEAN 0 +#define PROMO_DETAIL_LEN_MIN 20 +#define PROMO_DETAIL_LEN_MAX 60 + +/*** +*** SR_xxx Store Returns Defines +***/ +#define SR_RETURN_PCT 10 /* percentage of store sales that are returned */ + +/*** +*** SS_xxx Store Sales Defines +***/ +#define SS_MIN_SHIP_DELAY 2 /* minimum days from order to ship */ +#define SS_MAX_SHIP_DELAY 90 /* maximum days from order to ship */ +#define SS_QUANTITY_MAX "100" +#define SS_MARKUP_MAX "1.00" +#define SS_DISCOUNT_MAX "1.00" +#define SS_WHOLESALE_MAX "100.00" +#define SS_COUPON_MAX "0.50" + +/*** +*** WP_xxx Web Page Defines +***/ +#define WP_AUTOGEN_PCT 30 +#define WP_LINK_MIN 2 +#define WP_LINK_MAX 25 +#define WP_IMAGE_MIN 1 +#define WP_IMAGE_MAX 7 +#define WP_AD_MIN 0 +#define WP_AD_MAX 4 +#define WP_MAX_REC_DURATION \ + 1000 /* maximum time from start to end of record \ + */ +#define WP_IDLE_TIME_MAX 100 /* maximum time since last page access */ + +/*** +*** W_xxx Warehouse Defines +***/ +#define W_DESC_MIN 5 +#define W_SQFT_MIN 50000 +#define W_SQFT_MAX 1000000 +#define W_NAME_MIN 10 + +/*** +*** WR_xxx Web Returns Defines +***/ +#define WR_RETURN_PCT 10 /* percentage of web sales that are returned */ +#define WR_SHIP_LAG_MIN 2 /* lag time between receiving and returning */ +#define WR_SHIP_LAG_MAX 12 + +/*** +*** WEB_xxx Web Site Defines +***/ +#define WEB_START_DATE \ + DATE_MINIMUM /* range of open/close dates; actual dates can exceed these \ + values */ +#define WEB_END_DATE DATE_MAXIMUM /* due to staggered start of each site */ +#define WEB_DATE_STAGGER \ + 17 /* time between site creation on leading/trailing edge */ +#define WEB_PAGES_PER_SITE 123 /* number of pages on a web site */ +/* some of the web sites are completely replaced in the date range. */ +#define WEB_MORTALITY \ + 50 /* percentage of sites that "die" between start and end */ +#define WEB_IS_REPLACED(j) \ + ((j % (100 / WEB_MORTALITY)) == 0) /* does this site get replaced? */ +#define WEB_IS_REPLACEMENT(j) \ + ((j / (100 / WEB_MORTALITY)) % 2) /* is this the replacement? */ + +/*** + *** SOURCE SCHEMA CONSTANTS + ***/ +#define DAYS_PER_UPDATE 3 + +/*** +*** RS_xxx: Row and column sizes +***/ +/* sizes used in various tables */ +#define RS_BKEY 16 +/* table-specific sizes */ + +#define RS_BRND_NAME 50 +#define RS_C_SALUTATION 5 +#define RS_C_FIRST_NAME 20 +#define RS_C_LAST_NAME 30 +#define RS_C_BIRTH_COUNTRY 20 +#define RS_C_LOGIN 13 +#define RS_C_PASSWORD 13 +#define RS_C_EMAIL 50 +#define RS_C_PRIMARY_MACHINE_ID 15 +#define RS_C_SECONDARY_MACHINE_ID 15 +#define RS_CA_SUITE_NUMBER 10 +#define RS_CA_STREET_NAME 60 +#define RS_CA_STREET_TYPE 15 +#define RS_CA_CITY 60 +#define RS_CA_COUNTY 30 +#define RS_CA_STATE 2 +#define RS_CA_COUNTRY 20 +#define RS_CA_ZIP 10 +#define RS_CA_LOCATION_TYPE 20 +#define RS_CATG_DESC 20 +#define RS_CC_NAME 50 +#define RS_CC_CLASS 50 +#define RS_CC_HOURS 20 +#define RS_CC_MANAGER 40 +#define RS_CC_MARKET_MANAGER 40 +#define RS_CC_MARKET_CLASS 50 +#define RS_CC_MARKET_DESC 100 +#define RS_CC_DIVISION_NAME 50 +#define RS_CC_COMPANY_NAME 60 +#define RS_CC_SUITE_NUM 10 +#define RS_CC_STREET_NAME 60 +#define RS_CC_STREET_TYPE 15 +#define RS_CC_CITY 60 +#define RS_CC_COUNTY 30 +#define RS_CC_STATE 2 +#define RS_CC_COUNTRY 20 +#define RS_CC_ZIP 10 +#define RS_CD_GENDER 1 +#define RS_CD_MARITAL_STATUS 1 +#define RS_CD_EDUCATION_STATUS 20 +#define RS_CD_CREDIT_RATING 10 +#define RS_CP_DEPARTMENT 20 +#define RS_CLAS_DESC 100 +#define RS_CMPY_NAME 50 +#define RS_CP_DESCRIPTION 100 +#define RS_CP_TYPE 100 +#define RS_CTGR_NAME 25 +#define RS_CTGR_DESC 100 +#define RS_CUST_CREDIT 100 +#define RS_D_DAY_NAME 4 +#define RS_D_QUARTER_NAME 4 +#define RS_DVSN_NAME 50 +#define RS_HD_BUY_POTENTIAL 7 +#define RS_I_ITEM_DESC 200 +#define RS_I_BRAND 50 +#define RS_I_SUBCLASS 50 +#define RS_I_CLASS 50 +#define RS_I_SUBCATEGORY 50 +#define RS_I_CATEGORY 50 +#define RS_I_MANUFACT 50 +#define RS_I_SIZE 20 +#define RS_I_FORMULATION 20 +#define RS_I_FLAVOR 20 +#define RS_I_UNITS 10 +#define RS_I_CONTAINER 10 +#define RS_I_PRODUCT_NAME 50 +#define RS_MANF_NAME 50 +#define RS_MNGR_NAME 50 +#define RS_P_PROMO_NAME 50 +#define RS_P_CHANNEL_DETAILS 100 +#define RS_P_PURPOSE 15 +#define RS_PB_DESCRIPTION 100 +#define RS_PLIN_COMMENT 100 +#define RS_PROD_NAME 100 +#define RS_PROD_TYPE 100 +#define RS_R_REASON_DESCRIPTION 100 +#define RS_STORE_NAME 50 +#define RS_STORE_HOURS 20 +#define RS_S_STORE_MANAGER 40 +#define RS_S_GEOGRAPHY_CLASS 100 +#define RS_S_MARKET_DESC 100 +#define RS_S_MARKET_MANAGER 40 +#define RS_S_DIVISION_NAME 50 +#define RS_S_COMPANY_NAME 50 +#define RS_S_SUITE_NUM 10 +#define RS_S_STREET_NAME 60 +#define RS_S_STREET_TYPE 15 +#define RS_S_CITY 60 +#define RS_S_STATE 2 +#define RS_S_COUNTY 30 +#define RS_S_COUNTRY 30 +#define RS_S_ZIP 10 +#define RS_SM_TYPE 30 +#define RS_SM_CODE 10 +#define RS_SM_CONTRACT 20 +#define RS_SM_CARRIER 20 +#define RS_SBCT_NAME 100 +#define RS_SBCT_DESC 100 +#define RS_SUBC_NAME 100 +#define RS_SUBC_DESC 100 +#define RS_T_AM_PM 2 +#define RS_T_SHIFT 20 +#define RS_T_SUB_SHIFT 20 +#define RS_T_MEAL_TIME 20 +#define RS_W_WAREHOUSE_NAME 20 +#define RS_W_STREET_NAME 60 +#define RS_W_SUITE_NUM 10 +#define RS_W_STREET_TYPE 15 +#define RS_W_CITY 60 +#define RS_W_COUNTY 30 +#define RS_W_STATE 2 +#define RS_W_COUNTRY 20 +#define RS_W_ZIP 10 +#define RS_WEB_MANAGER 50 +#define RS_WEB_NAME 50 +#define RS_WEB_CLASS 50 +#define RS_WEB_MARKET_CLASS 50 +#define RS_WEB_MARKET_DESC 100 +#define RS_WEB_MARKET_MANAGER 40 +#define RS_WEB_COMPANY_NAME 100 +#define RS_WEB_SUITE_NUMBER 10 +#define RS_WEB_STREET_NAME 60 +#define RS_WEB_STREET_TYPE 15 +#define RS_WEB_CITY 60 +#define RS_WEB_COUNTY 30 +#define RS_WEB_STATE 2 +#define RS_WEB_COUNTRY 20 +#define RS_WEB_ZIP 10 +#define RS_WP_URL 100 +#define RS_WEB_TYPE 50 +#define RS_WRHS_DESC 100 +#define RS_WORD_COMMENT 100 +#define RS_ZIPG_ZIP 5 +#endif /* CONSTANTS_H */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/date.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/date.h new file mode 100644 index 0000000000000..19a14d106799c --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/date.h @@ -0,0 +1,54 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef R_DATE_H +#define R_DATE_H + +#include "mathops.h" + +typedef struct DATE_T { + int flags; + int year; + int month; + int day; + int julian; +} date_t; + +date_t* mk_date(void); + +int jtodt(date_t* dest, int i); +int strtodt(date_t* dest, char* s); +date_t* strtodate(char* str); +int strtotime(char* str); + +char* dttostr(date_t* d); +int dttoj(date_t* d); + +int date_t_op(date_t* dest, int o, date_t* d1, date_t* d2); +int set_dow(date_t* d); +int is_leap(int year); +int day_number(date_t* d); +int date_part(date_t* d, int p); +int set_outfile(int i); +int getDateWeightFromJulian(int jDay, int nDistribution); +#define CENTURY_SHIFT 20 /* years before this are assumed to be 2000's */ +/* + * DATE OPERATORS + */ +#define OP_FIRST_DOM 0x01 /* get date of first day of current month */ +#define OP_LAST_DOM \ + 0x02 /* get date of last day of current month; LY == 2/28) */ +#define OP_SAME_LY 0x03 /* get date for same day/month, last year */ +#define OP_SAME_LQ 0x04 /* get date for same offset in the prior quarter */ + +extern char* weekday_names[]; + +#endif /* R_DATE_H */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/dbgen_version.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/dbgen_version.h new file mode 100644 index 0000000000000..05e228d2f01b1 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/dbgen_version.h @@ -0,0 +1,23 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef DBGEN_VERSION_H +#define DBGEN_VERSION_H + +#include "dist.h" + +int mk_dbgen_version( + void* pDest, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); +int pr_dbgen_version(void* pSrc); +int ld_dbgen_version(void* pSrc); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/dcomp.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/dcomp.h new file mode 100644 index 0000000000000..3e02672e3b996 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/dcomp.h @@ -0,0 +1,62 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef DCOMP_H +#define DCOMP_H + +#include "config.h" +#include "dist.h" +#include "grammar.h" +#include "porting.h" + +/* + * query template grammar definition + */ +#define TKN_UNKNOWN 0 +#define TKN_CREATE 1 +#define TKN_WEIGHTS 2 +#define TKN_TYPES 3 +#define TKN_INCLUDE 4 +#define TKN_SET 5 +#define TKN_VARCHAR 6 +#define TKN_INT 7 +#define TKN_ADD 8 +#define TKN_DATE 9 +#define TKN_DECIMAL 10 +#define TKN_NAMES 11 +#define MAX_TOKEN 11 + +int ProcessDistribution(char* s, token_t* t); +int ProcessTypes(char* s, token_t* t); +int ProcessInclude(char* s, token_t* t); +int ProcessSet(char* s, token_t* t); +int ProcessAdd(char* s, token_t* t); + +#ifdef DECLARER +token_t dcomp_tokens[MAX_TOKEN + 2] = { + {TKN_UNKNOWN, "", NULL}, + {TKN_CREATE, "create", ProcessDistribution}, + {TKN_WEIGHTS, "weights", NULL}, + {TKN_TYPES, "types", NULL}, + {TKN_INCLUDE, "#include", ProcessInclude}, + {TKN_SET, "set", ProcessSet}, + {TKN_VARCHAR, "varchar", NULL}, + {TKN_INT, "int", NULL}, + {TKN_ADD, "add", ProcessAdd}, + {TKN_DATE, "date", NULL}, + {TKN_DECIMAL, "decimal", NULL}, + {TKN_NAMES, "names", NULL}, + {-1, "", NULL}}; +#else +extern token_t tokens[]; +#endif + +#endif /* DCOMP_H */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/decimal.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/decimal.h new file mode 100644 index 0000000000000..bbcb0c3dfb5eb --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/decimal.h @@ -0,0 +1,36 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef R_DECIMAL_H +#define R_DECIMAL_H +#include +#include "config.h" +#include "dist.h" +#include "mathops.h" +#include "porting.h" + +#define FL_INIT 0x0004 + +decimal_t* mk_decimal(int s, int p); + +int itodec(decimal_t* dest, int i); +int ftodec(decimal_t* d, double f); +int strtodec(decimal_t* d, char* src); + +int dectostr(char* dest, decimal_t* d); +int dectof(double* dest, decimal_t*); +#define dectoi(d) atoi(d->number) + +int decimal_t_op(decimal_t* dest, int o, decimal_t* d1, decimal_t* d2); +void print_decimal(int nColumn, decimal_t* d, int s); +void set_precision(decimal_t* d, int sie, int precision); +#define NegateDecimal(d) (d)->number *= -1 +#endif /* R_DECIMAL_H */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/dist.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/dist.h new file mode 100644 index 0000000000000..d0c62331b3b32 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/dist.h @@ -0,0 +1,3985 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#pragma once +#include +#include +#include +#include +#include +#include "algorithm" +#include "columns.h" +#include "config.h" +#include "iostream" +#include "tables.h" +#include "vector" + +#ifndef STREAMS_H +#define STREAMS_H +#endif +#include "constants.h" +#include "tables.h" + +#ifndef R_DIST_H +#define R_DIST_H +#endif + +/*** + *** RELEASE INFORMATION + ***/ +#define VERSION 2 +#define RELEASE 10 +#define MODIFICATION 0 +#define PATCH "" +#define COPYRIGHT "Transaction Processing Performance Council (TPC)" +#define C_DATES "2001 - 2018" + +#define D_NAME_LEN 20 +#define MAX_STREAM 805 + +#define RS_W_STORE_NAME 50 +#define RS_W_STORE_MGR 40 +#define RS_W_MARKET_MGR 40 +#define RS_W_MARKET_DESC 100 +#define STORE_MIN_TAX_PERCENTAGE "0.00" +#define STORE_MAX_TAX_PERCENTAGE "0.11" + +/*** + *** STORE_xxx Store Defines + ***/ +#define STORE_MIN_DAYS_OPEN 5 +#define STORE_MAX_DAYS_OPEN 500 +#define STORE_CLOSED_PCT 30 +#define STORE_MIN_REV_GROWTH "-0.05" +#define STORE_MAX_REV_GROWTH "0.50" +#define STORE_DESC_MIN 15 + +#define RS_VERSION_LENGTH 100 +#define RS_CMDLINARGS_LENGTH 200 + +#define OPT_NONE 0x00 +#define OPT_FLG 0x01 /* option is a flag; no parameter */ +#define OPT_INT 0x02 /* argument is an integer */ +#define OPT_STR 0x04 /* argument is a string */ +#define OPT_NOP 0x08 /* flags non-operational options */ +#define OPT_SUB 0x10 /* sub-option defined */ +#define OPT_ADV 0x20 /* advanced option */ +#define OPT_SET \ + 0x40 /* not changeable -- used for default/file/command precedence */ +#define OPT_DFLT 0x80 /* param set to non-zero default */ +#define OPT_MULTI 0x100 /* param may be set repeatedly */ +#define OPT_HIDE 0x200 /* hidden option -- not listed in usage */ +#define TYPE_MASK 0x07 + +/* + * Flag field definitions used in tdefs[] + */ +#define FL_NONE 0x0000 /* this table is not defined */ +#define FL_NOP 0x0001 /* this table is not defined */ +#define FL_DATE_BASED 0x0002 /* this table is produced in date order */ +#define FL_CHILD 0x0004 /* this table is the child in a parent/child link */ +#define FL_OPEN 0x0008 /* this table has a valid output destination */ +#define FL_DUP_NAME 0x0010 /* to keep find_table() from complaining twice */ +#define FL_TYPE_2 \ + 0x0020 /* this dimension keeps history -- rowcount shows unique entities \ + (not including revisions) */ +#define FL_SMALL 0x0040 /* this table has low rowcount; used by address.c */ +#define FL_SPARSE 0x0080 +/* unused 0x0100 */ +#define FL_NO_UPDATE \ + 0x0200 /* this table is not altered by the update process */ +#define FL_SOURCE_DDL 0x0400 /* table in the souce schema */ +#define FL_JOIN_ERROR 0x0800 /* join called without an explicit rule */ +#define FL_PARENT 0x1000 /* this table has a child in nParam */ +#define FL_FACT_TABLE 0x2000 +#define FL_PASSTHRU 0x4000 /* verify routine uses warehouse without change */ +#define FL_VPRINT 0x8000 /* verify routine includes print function */ + +#define JMS 1 + +typedef HUGE_TYPE ds_key_t; + +struct DSDGenContext; + +typedef struct DIST_T { + int* type_vector; + int** weight_sets; + int* maximums; + int** value_sets; + char* strings; + char* names; + int size; +} dist_t; + +struct DBGEN_VERSION_TBL { + char szVersion[RS_VERSION_LENGTH + 1]; + char szDate[26]; + char szTime[26]; + char szCmdLineArgs[RS_CMDLINARGS_LENGTH + 1]; +}; + +typedef struct D_IDX_T { + char name[D_NAME_LEN + 1]; + int index; + int nAllocatedLength; + int nRemainingStrSpace; + int offset; + int str_space; + int name_space; + int length; + int w_width; + int v_width; + int flags; + dist_t* dist; +} d_idx_t; + +typedef struct DISTINDEX_T { + int nDistCount; + int nAllocatedCount; + d_idx_t* pEntries; +} distindex_t; + +/* + * a precise decimal data type, using scaled integer + * arithmetic. + */ +typedef struct DECIMAL_T { + int flags; + int precision; + int scale; + ds_key_t number; +} decimal_t; + +typedef struct OPTION_T { + const char* name; + int flags; + int index; + const char* usage; + int (*action)( + const char* szPName, + const char* optarg, + DSDGenContext& dsdGenContext); + const char* dflt; +} option_t; + +typedef struct DS_PRICING_T { + decimal_t wholesale_cost; + decimal_t list_price; + decimal_t sales_price; + int quantity; + decimal_t ext_discount_amt; + decimal_t ext_sales_price; + decimal_t ext_wholesale_cost; + decimal_t ext_list_price; + decimal_t tax_pct; + decimal_t ext_tax; + decimal_t coupon_amt; + decimal_t ship_cost; + decimal_t ext_ship_cost; + decimal_t net_paid; + decimal_t net_paid_inc_tax; + decimal_t net_paid_inc_ship; + decimal_t net_paid_inc_ship_tax; + decimal_t net_profit; + decimal_t refunded_cash; + decimal_t reversed_charge; + decimal_t store_credit; + decimal_t fee; + decimal_t net_loss; +} ds_pricing_t; + +typedef struct DS_ADDR_T { + char suite_num[RS_CC_SUITE_NUM + 1]; + int street_num; + char* street_name1; + char* street_name2; + char* street_type; + char* city; + char* county; + char* state; + char country[RS_CC_COUNTRY + 1]; + int zip; + int plus4; + int gmt_offset; +} ds_addr_t; + +/* + * STORE_SALES table structure + */ +struct W_STORE_SALES_TBL { + ds_key_t ss_sold_date_sk; + ds_key_t ss_sold_time_sk; + ds_key_t ss_sold_item_sk; + ds_key_t ss_sold_customer_sk; + ds_key_t ss_sold_cdemo_sk; + ds_key_t ss_sold_hdemo_sk; + ds_key_t ss_sold_addr_sk; + ds_key_t ss_sold_store_sk; + ds_key_t ss_sold_promo_sk; + ds_key_t ss_ticket_number; + ds_pricing_t ss_pricing; +}; + +/* + * STORE_RETURNS table structure + */ +struct W_STORE_RETURNS_TBL { + ds_key_t sr_returned_date_sk; + ds_key_t sr_returned_time_sk; + ds_key_t sr_item_sk; + ds_key_t sr_customer_sk; + ds_key_t sr_cdemo_sk; + ds_key_t sr_hdemo_sk; + ds_key_t sr_addr_sk; + ds_key_t sr_store_sk; + ds_key_t sr_reason_sk; + ds_key_t sr_ticket_number; + ds_pricing_t sr_pricing; +}; + +typedef struct RNG_T { + int nUsed; + int nUsedPerRow; + long nSeed; + long nInitialSeed; /* used to allow skip_row() to back up */ + int nColumn; /* column where this stream is used */ + int nTable; /* table where this stream is used */ + int nDuplicateOf; /* duplicate streams allow independent tables to share + data streams */ +#ifdef JMS + ds_key_t nTotal; +#endif +} rng_t; + +struct W_DATE_TBL { + ds_key_t d_date_sk; + char d_date_id[RS_BKEY + 1]; + /* this is generated at output from d_date_sk */ + /* date_t d_date; */ + int d_month_seq; + int d_week_seq; + int d_quarter_seq; + int d_year; + int d_dow; + int d_moy; + int d_dom; + int d_qoy; + int d_fy_year; + int d_fy_quarter_seq; + int d_fy_week_seq; + char* d_day_name; + /* char d_quarter_name[RS_D_QUARTER_NAME + 1]; derived at print + * time */ + int d_holiday; + int d_weekend; + int d_following_holiday; + int d_first_dom; + int d_last_dom; + int d_same_day_ly; + int d_same_day_lq; + int d_current_day; + int d_current_week; + int d_current_month; + int d_current_quarter; + int d_current_year; +}; + +/* + * STORE table structure + */ +struct W_STORE_TBL { + ds_key_t store_sk; + char store_id[RS_BKEY + 1]; + ds_key_t rec_start_date_id; + ds_key_t rec_end_date_id; + ds_key_t closed_date_id; + char store_name[RS_W_STORE_NAME + 1]; + int employees; + int floor_space; + char* hours; + char store_manager[RS_W_STORE_MGR + 1]; + int market_id; + decimal_t dTaxPercentage; + char* geography_class; + char market_desc[RS_W_MARKET_DESC + 1]; + char market_manager[RS_W_MARKET_MGR + 1]; + ds_key_t division_id; + char* division_name; + ds_key_t company_id; + char* company_name; + ds_addr_t address; +}; + +/* + * CALL_CENTER table structure + */ +struct CALL_CENTER_TBL { + ds_key_t cc_call_center_sk; + char cc_call_center_id[RS_BKEY + 1]; + ds_key_t cc_rec_start_date_id; + ds_key_t cc_rec_end_date_id; + ds_key_t cc_closed_date_id; + ds_key_t cc_open_date_id; + char cc_name[RS_CC_NAME + 1]; + char* cc_class; + int cc_employees; + int cc_sq_ft; + char* cc_hours; + char cc_manager[RS_CC_MANAGER + 1]; + int cc_market_id; + char cc_market_class[RS_CC_MARKET_CLASS + 1]; + char cc_market_desc[RS_CC_MARKET_DESC + 1]; + char cc_market_manager[RS_CC_MARKET_MANAGER + 1]; + int cc_division_id; + char cc_division_name[RS_CC_DIVISION_NAME + 1]; + int cc_company; + char cc_company_name[RS_CC_COMPANY_NAME + 1]; + ds_addr_t cc_address; + decimal_t cc_tax_percentage; +}; + +struct SCALING_T { + ds_key_t kBaseRowcount; + ds_key_t kNextInsertValue; + int nUpdatePercentage; + ds_key_t kDayRowcount[6]; +}; + +/* + * CATALOG_PAGE table structure + */ +struct CATALOG_PAGE_TBL { + ds_key_t cp_catalog_page_sk; + char cp_catalog_page_id[RS_BKEY + 1]; + ds_key_t cp_start_date_id; + ds_key_t cp_end_date_id; + char cp_department[RS_CP_DEPARTMENT + 1]; + int cp_catalog_number; + int cp_catalog_page_number; + char cp_description[RS_CP_DESCRIPTION + 1]; + char* cp_type; +}; + +/* + * CATALOG_RETURNS table structure + */ +struct W_CATALOG_RETURNS_TBL { + ds_key_t cr_returned_date_sk; + ds_key_t cr_returned_time_sk; + ds_key_t cr_item_sk; + ds_key_t cr_refunded_customer_sk; + ds_key_t cr_refunded_cdemo_sk; + ds_key_t cr_refunded_hdemo_sk; + ds_key_t cr_refunded_addr_sk; + ds_key_t cr_returning_customer_sk; + ds_key_t cr_returning_cdemo_sk; + ds_key_t cr_returning_hdemo_sk; + ds_key_t cr_returning_addr_sk; + ds_key_t cr_call_center_sk; + ds_key_t cr_catalog_page_sk; + ds_key_t cr_ship_mode_sk; + ds_key_t cr_warehouse_sk; + ds_key_t cr_reason_sk; + ds_key_t cr_order_number; + ds_pricing_t cr_pricing; + decimal_t cr_fee; + decimal_t cr_refunded_cash; + decimal_t cr_reversed_charge; + decimal_t cr_store_credit; + decimal_t cr_net_loss; +}; + +/* + * CATALOG_SALES table structure + */ +struct W_CATALOG_SALES_TBL { + ds_key_t cs_sold_date_sk; + ds_key_t cs_sold_time_sk; + ds_key_t cs_ship_date_sk; + ds_key_t cs_bill_customer_sk; + ds_key_t cs_bill_cdemo_sk; + ds_key_t cs_bill_hdemo_sk; + ds_key_t cs_bill_addr_sk; + ds_key_t cs_ship_customer_sk; + ds_key_t cs_ship_cdemo_sk; + ds_key_t cs_ship_hdemo_sk; + ds_key_t cs_ship_addr_sk; + ds_key_t cs_call_center_sk; + ds_key_t cs_catalog_page_sk; + ds_key_t cs_ship_mode_sk; + ds_key_t cs_warehouse_sk; + ds_key_t cs_sold_item_sk; + ds_key_t cs_promo_sk; + ds_key_t cs_order_number; + ds_pricing_t cs_pricing; +}; + +/* + * CUSTOMER table structure + */ +struct W_CUSTOMER_TBL { + ds_key_t c_customer_sk; + char c_customer_id[RS_BKEY + 1]; + ds_key_t c_current_cdemo_sk; + ds_key_t c_current_hdemo_sk; + ds_key_t c_current_addr_sk; + int c_first_shipto_date_id; + int c_first_sales_date_id; + char* c_salutation; + char* c_first_name; + char* c_last_name; + int c_preferred_cust_flag; + int c_birth_day; + int c_birth_month; + int c_birth_year; + char* c_birth_country; + char c_login[RS_C_LOGIN + 1] = {}; + char c_email_address[RS_C_EMAIL + 1]; + int c_last_review_date; +}; + +/* + * CUSTOMER_ADDRESS table structure + */ +struct W_CUSTOMER_ADDRESS_TBL { + ds_key_t ca_addr_sk; + char ca_addr_id[RS_BKEY + 1]; + ds_addr_t ca_address; + char* ca_location_type; +}; + +/* + * CUSTOMER_DEMOGRAPHICS table structure + */ +struct W_CUSTOMER_DEMOGRAPHICS_TBL { + ds_key_t cd_demo_sk; + char* cd_gender; + char* cd_marital_status; + char* cd_education_status; + int cd_purchase_estimate; + char* cd_credit_rating; + int cd_dep_count; + int cd_dep_employed_count; + int cd_dep_college_count; +}; + +/* + * INVENTORY table structure + */ +struct W_INVENTORY_TBL { + ds_key_t inv_date_sk; + ds_key_t inv_item_sk; + ds_key_t inv_warehouse_sk; + int inv_quantity_on_hand; +}; + +/* + * TIME_DIM table structure + */ +struct W_TIME_TBL { + ds_key_t t_time_sk; + char t_time_id[RS_BKEY + 1]; + int t_time; + int t_hour; + int t_minute; + int t_second; + char* t_am_pm; + char* t_shift; + char* t_sub_shift; + char* t_meal_time; +}; + +/* + * INCOME_BAND table structure + */ +struct W_INCOME_BAND_TBL { + int ib_income_band_id; + int ib_lower_bound; + int ib_upper_bound; +}; + +/* + * HOUSEHOLD_DEMOGRAPHICS table structure + */ +struct W_HOUSEHOLD_DEMOGRAPHICS_TBL { + ds_key_t hd_demo_sk; + ds_key_t hd_income_band_id; + char* hd_buy_potential; + int hd_dep_count; + int hd_vehicle_count; +}; + +/* + * SHIP_MODE table structure + */ +struct W_SHIP_MODE_TBL { + ds_key_t sm_ship_mode_sk; + char sm_ship_mode_id[RS_BKEY + 1]; + char* sm_type; + char* sm_code; + char* sm_carrier; + char sm_contract[RS_SM_CONTRACT + 1]; +}; + +/* + * PROMOTION table structure + */ +struct W_PROMOTION_TBL { + ds_key_t p_promo_sk; + char p_promo_id[RS_BKEY + 1]; + ds_key_t p_start_date_id; + ds_key_t p_end_date_id; + ds_key_t p_item_sk; + decimal_t p_cost; + int p_response_target; + char p_promo_name[RS_P_PROMO_NAME + 1]; + int p_channel_dmail; + int p_channel_email; + int p_channel_catalog; + int p_channel_tv; + int p_channel_radio; + int p_channel_press; + int p_channel_event; + int p_channel_demo; + char p_channel_details[RS_P_CHANNEL_DETAILS + 1]; + char* p_purpose; + int p_discount_active; +}; + +/* + * REASON table structure + */ +struct W_REASON_TBL { + ds_key_t r_reason_sk; + char r_reason_id[RS_BKEY + 1]; + char* r_reason_description; +}; + +/* + * WAREHOUSE table structure + */ +struct W_WAREHOUSE_TBL { + ds_key_t w_warehouse_sk; + char w_warehouse_id[RS_BKEY + 1]; + char w_warehouse_name[RS_W_WAREHOUSE_NAME + 1]; + int w_warehouse_sq_ft; + ds_addr_t w_address; +}; + +/* + * WEB_SALES table structure + */ +struct W_WEB_SALES_TBL { + ds_key_t ws_sold_date_sk; + ds_key_t ws_sold_time_sk; + ds_key_t ws_ship_date_sk; + ds_key_t ws_item_sk; + ds_key_t ws_bill_customer_sk; + ds_key_t ws_bill_cdemo_sk; + ds_key_t ws_bill_hdemo_sk; + ds_key_t ws_bill_addr_sk; + ds_key_t ws_ship_customer_sk; + ds_key_t ws_ship_cdemo_sk; + ds_key_t ws_ship_hdemo_sk; + ds_key_t ws_ship_addr_sk; + ds_key_t ws_web_page_sk; + ds_key_t ws_web_site_sk; + ds_key_t ws_ship_mode_sk; + ds_key_t ws_warehouse_sk; + ds_key_t ws_promo_sk; + ds_key_t ws_order_number; + ds_pricing_t ws_pricing; +}; + +/* + * WEB_RETURNS table structure + */ +struct W_WEB_RETURNS_TBL { + ds_key_t wr_returned_date_sk; + ds_key_t wr_returned_time_sk; + ds_key_t wr_item_sk; + ds_key_t wr_refunded_customer_sk; + ds_key_t wr_refunded_cdemo_sk; + ds_key_t wr_refunded_hdemo_sk; + ds_key_t wr_refunded_addr_sk; + ds_key_t wr_returning_customer_sk; + ds_key_t wr_returning_cdemo_sk; + ds_key_t wr_returning_hdemo_sk; + ds_key_t wr_returning_addr_sk; + ds_key_t wr_web_page_sk; + ds_key_t wr_reason_sk; + ds_key_t wr_order_number; + ds_pricing_t wr_pricing; +}; + +/* + * WEB_PAGE table structure + */ +struct W_WEB_PAGE_TBL { + ds_key_t wp_page_sk; + char wp_page_id[RS_BKEY + 1]; + char wp_site_id[RS_BKEY + 1]; + ds_key_t wp_rec_start_date_id; + ds_key_t wp_rec_end_date_id; + ds_key_t wp_creation_date_sk; + ds_key_t wp_access_date_sk; + int wp_autogen_flag; + ds_key_t wp_customer_sk; + char wp_url[RS_WP_URL + 1]; + char* wp_type; + int wp_char_count; + int wp_link_count; + int wp_image_count; + int wp_max_ad_count; +}; + +/* + * ITEM table structure + */ +struct W_ITEM_TBL { + ds_key_t i_item_sk; + char i_item_id[RS_BKEY + 1]; + ds_key_t i_rec_start_date_id; + ds_key_t i_rec_end_date_id; + char i_item_desc[RS_I_ITEM_DESC + 1]; + decimal_t i_current_price; /* list price */ + decimal_t i_wholesale_cost; + ds_key_t i_brand_id; + char i_brand[RS_I_BRAND + 1]; + ds_key_t i_class_id; + char* i_class; + ds_key_t i_category_id; + char* i_category; + ds_key_t i_manufact_id; + char i_manufact[RS_I_MANUFACT + 1]; + char* i_size; + char i_formulation[RS_I_FORMULATION + 1]; + char* i_color; + char* i_units; + char* i_container; + ds_key_t i_manager_id; + char i_product_name[RS_I_PRODUCT_NAME + 1]; + ds_key_t i_promo_sk; +}; + +/* + * WEB_SITE table structure + */ +struct W_WEB_SITE_TBL { + ds_key_t web_site_sk; + char web_site_id[RS_BKEY + 1]; + ds_key_t web_rec_start_date_id; + ds_key_t web_rec_end_date_id; + char web_name[RS_WEB_NAME + 1]; + ds_key_t web_open_date; + ds_key_t web_close_date; + char web_class[RS_WEB_CLASS + 1]; + char web_manager[RS_WEB_MANAGER + 1]; + int web_market_id; + char web_market_class[RS_WEB_MARKET_CLASS + 1]; + char web_market_desc[RS_WEB_MARKET_DESC + 1]; + char web_market_manager[RS_WEB_MARKET_MANAGER + 1]; + int web_company_id; + char web_company_name[RS_WEB_COMPANY_NAME + 1]; + ds_addr_t web_address; + decimal_t web_tax_percentage; +}; + +/* + * general table descriptions. + * NOTE: This table contains the constant elements in the table descriptions; it + * must be kept in sync with the declararions of assocaited functions, found in + * tdef_functions.h + */ + +typedef struct TDEF_T { + const char* name; /* -- name of the table; */ + const char* abreviation; /* -- shorthand name of the table */ + unsigned int flags; /* -- control table options */ + int nFirstColumn; /* -- first column/RNG for this table */ + int nLastColumn; /* -- last column/RNG for this table */ + int nTableIndex; /* used for rowcount calculations */ + int nParam; /* -- additional table param (revision count, child number, + etc.) */ + FILE* outfile; /* -- output destination */ + int nUpdateSize; /* -- percentage of base rowcount in each update set (basis + points) */ + int nNewRowPct; + int nNullPct; /* percentage of rows with nulls (basis points) */ + ds_key_t kNullBitMap; /* colums that should be NULL in the current row */ + ds_key_t kNotNullBitMap; /* columns that are defined NOT NULL */ + ds_key_t* + arSparseKeys; /* sparse key set for table; used if FL_SPARSE is set */ +} tdef; + +int read_file( + const char* param_name, + const char* arg, + DSDGenContext& dsdGenContext); +int usage( + const char* param_name, + const char* msg, + DSDGenContext& dsdGenContext); +int SetScaleIndex( + const char* szName, + const char* szValue, + DSDGenContext& dsdGenContext); +int printReleaseInfo( + const char* param, + const char* val, + DSDGenContext& dsdGenContext); +static void print_options( + struct OPTION_T* o, + int bShowOptional, + DSDGenContext& dsdGenContext); + +static folly::Synchronized> idx_; +static std::once_flag initFlag_; + +// DSDGenContext to access global variables. +struct DSDGenContext { + struct DBGEN_VERSION_TBL g_dbgen_version; + + struct W_STORE_SALES_TBL g_w_store_sales; + int *pStoreSalesItemPermutation, *pCatalogSalesItemPermutation, + *pWebSalesItemPermutation; + int nStoreSalesItemCount, nCatalogSalesItemCount, nWebSalesItemCount; + int nStoreSalesItemIndex, nCatalogSalesItemIndex, nWebSalesItemIndex; + ds_key_t jDate, kNewDateIndex; + int nTicketItemBase = 1; + + struct W_STORE_RETURNS_TBL g_w_store_returns; + struct DIST_T dist; + option_t options[26] = { + {"ABREVIATION", OPT_STR, 0, "build table with abreviation ", NULL, ""}, + {"DELIMITER", + OPT_STR | OPT_ADV, + 1, + "use as output field separator", + NULL, + "|"}, + {"DIR", OPT_STR, 2, "generate tables in directory ", NULL, "."}, + {"DISTRIBUTIONS", + OPT_STR | OPT_ADV, + 3, + "read distributions from file ", + NULL, + "NONE"}, + {"FORCE", + OPT_FLG | OPT_ADV, + 4, + "over-write data files without prompting", + NULL, + "N"}, + {"HELP", OPT_INT, 5, "display this message", usage, "0"}, + {"PARAMS", OPT_STR, 6, "read parameters from file ", read_file, ""}, + {"PROG", + OPT_STR | OPT_HIDE | OPT_SET, + 7, + "DO NOT MODIFY", + NULL, + "dsdgen"}, + {"QUIET", OPT_FLG, 8, "disable all output to stdout/stderr", NULL, "N"}, + {"SCALE", + OPT_STR, + 9, + "volume of data to generate in GB", + SetScaleIndex, + "1"}, + {"SUFFIX", + OPT_STR | OPT_ADV, + 10, + "use as output file suffix", + NULL, + ".dat"}, + {"TABLE", OPT_STR, 11, "build only table ", NULL, "ALL"}, + {"TERMINATE", + OPT_FLG | OPT_ADV, + 12, + "end each record with a field delimiter", + NULL, + "Y"}, + {"UPDATE", OPT_INT, 13, "generate update data set ", NULL, ""}, + {"VERBOSE", OPT_FLG, 14, "enable verbose output", NULL, "N"}, + {"_SCALE_INDEX", + OPT_INT | OPT_HIDE, + 15, + "Scale band; used for dist lookups", + NULL, + "1"}, + {"PARALLEL", OPT_INT, 16, "build data in separate chunks", NULL, ""}, + {"CHILD", + OPT_INT, + 17, + "generate th chunk of the parallelized data", + NULL, + "1"}, + {"CHKSEEDS", + OPT_FLG | OPT_HIDE, + 18, + "validate RNG usage for parallelism", + NULL, + "N"}, + {"RELEASE", + OPT_FLG, + 19, + "display the release information", + printReleaseInfo, + "N"}, + {"_FILTER", OPT_FLG, 20, "output data to stdout", NULL, "N"}, + {"VALIDATE", OPT_FLG, 21, "produce rows for data validation", NULL, "N"}, + {"VCOUNT", + OPT_INT | OPT_ADV, + 22, + "set number of validation rows to be produced", + NULL, + "50"}, + {"VSUFFIX", + OPT_STR | OPT_ADV, + 23, + "set file suffix for data validation", + NULL, + ".vld"}, + {"RNGSEED", OPT_INT | OPT_ADV, 24, "set RNG seed", NULL, "19620718"}}; + + char* params[23 + 2]; + + struct W_DATE_TBL g_w_date; + + struct W_STORE_TBL g_w_store; + + struct CALL_CENTER_TBL g_w_call_center; + + struct W_WEB_PAGE_TBL g_w_web_page; + + struct W_ITEM_TBL g_w_item; + + struct W_WEB_SITE_TBL g_w_web_site; + + struct CATALOG_PAGE_TBL g_w_catalog_page; + + struct W_CATALOG_RETURNS_TBL g_w_catalog_returns; + + struct W_CATALOG_SALES_TBL g_w_catalog_sales; + + struct W_CUSTOMER_TBL g_w_customer; + + struct W_CUSTOMER_ADDRESS_TBL g_w_customer_address; + + struct W_CUSTOMER_DEMOGRAPHICS_TBL g_w_customer_demographics; + + struct W_INVENTORY_TBL g_w_inventory; + + struct W_TIME_TBL g_w_time; + + struct W_INCOME_BAND_TBL g_w_income_band; + + struct W_HOUSEHOLD_DEMOGRAPHICS_TBL g_w_household_demographics; + + struct W_SHIP_MODE_TBL g_w_ship_mode; + + struct W_PROMOTION_TBL g_w_promotion; + + struct W_REASON_TBL g_w_reason; + + struct W_WAREHOUSE_TBL g_w_warehouse; + + struct W_WEB_SALES_TBL g_w_web_sales; + + struct W_WEB_RETURNS_TBL g_w_web_returns; + + SCALING_T arRowcount[MAX_TABLE + 1]; + + int arUpdateDates[6]; + int arInventoryUpdateDates[6]; + + int arScaleVolume[9] = {1, 10, 100, 300, 1000, 3000, 10000, 30000, 100000}; + + int init_rand_init; + int mk_address_init; + int setUpdateDateRange_init; + int mk_dbgen_version_init; + int getCatalogNumberFromPage_init; + int checkSeeds_init; + int dateScaling_init; + int mk_w_call_center_init; + int mk_w_catalog_page_init; + int mk_master_catalog_sales_init; + int dectostr_init; + int date_join_init; + int setSCDKeys_init; + int scd_join_init; + int matchSCDSK_init; + int skipDays_init; + int mk_w_catalog_returns_init; + int mk_detail_catalog_sales_init; + int mk_w_customer_init; + int mk_w_date_init; + int mk_w_inventory_init; + int mk_w_item_init; + int mk_w_promotion_init; + int mk_w_reason_init; + int mk_w_ship_mode_init; + int mk_w_store_returns_init; + int mk_master_store_sales_init; + int mk_master_web_sales_init; + int mk_detail_web_sales_init; + int mk_w_store_init; + int mk_w_web_page_init; + int mk_w_web_returns_init; + int mk_master_init; + int mk_detail_init; + int mk_w_web_site_init; + int mk_cust_init; + int mk_order_init; + int mk_part_init; + int mk_supp_init; + int dbg_text_init; + int find_dist_init; + int cp_join_init; + int web_join_init; + int set_pricing_init; + int init_params_init; + int get_rowcount_init; + + tdef s_tdefs[38] = { + {"s_brand", + "s_br", + FL_NOP | FL_SOURCE_DDL, + S_BRAND_START, + S_BRAND_END, + S_BRAND, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_customer_address", + "s_ca", + FL_SOURCE_DDL | FL_PASSTHRU, + S_CUSTOMER_ADDRESS_START, + S_CUSTOMER_ADDRESS_END, + S_CUSTOMER_ADDRESS, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_call_center", + "s_cc", + FL_SOURCE_DDL, + S_CALL_CENTER_START, + S_CALL_CENTER_END, + S_CALL_CENTER, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x02, + NULL}, + {"s_catalog", + "s_ct", + FL_SOURCE_DDL | FL_NOP, + S_CATALOG_START, + S_CATALOG_END, + S_CATALOG, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_catalog_order", + "s_cord", + FL_SOURCE_DDL | FL_PARENT | FL_DATE_BASED, + S_CATALOG_ORDER_START, + S_CATALOG_ORDER_END, + S_CATALOG_ORDER, + S_CATALOG_ORDER_LINEITEM, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_catalog_order_lineitem", + "s_cl", + FL_SOURCE_DDL | FL_CHILD | FL_PARENT, + S_CATALOG_ORDER_LINEITEM_START, + S_CATALOG_ORDER_LINEITEM_END, + S_CATALOG_ORDER_LINEITEM, + S_CATALOG_RETURNS, + NULL, + 0, + 0, + 0, + 0x0, + 0x07, + NULL}, + {"s_catalog_page", + "s_cp", + FL_SOURCE_DDL | FL_PASSTHRU, + S_CATALOG_PAGE_START, + S_CATALOG_PAGE_END, + S_CATALOG_PAGE, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x033, + NULL}, + {"s_catalog_promotional_item", + "s_ci", + FL_NOP | FL_SOURCE_DDL, + S_CATALOG_PROMOTIONAL_ITEM_START, + S_CATALOG_PROMOTIONAL_ITEM_END, + S_CATALOG_PROMOTIONAL_ITEM, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_catalog_returns", + "s_cr", + FL_SOURCE_DDL | FL_CHILD, + S_CATALOG_RETURNS_START, + S_CATALOG_RETURNS_END, + S_CATALOG_RETURNS, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0E, + NULL}, + {"s_category", + "s_cg", + FL_NOP | FL_SOURCE_DDL, + S_CATEGORY_START, + S_CATEGORY_END, + S_CATEGORY, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_class", + "s_cl", + FL_NOP | FL_SOURCE_DDL, + S_CLASS_START, + S_CLASS_END, + S_CLASS, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_company", + "s_co", + FL_NOP | FL_SOURCE_DDL, + S_COMPANY_START, + S_COMPANY_END, + S_COMPANY, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_customer", + "s_cu", + FL_SOURCE_DDL, + S_CUSTOMER_START, + S_CUSTOMER_END, + S_CUSTOMER, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_division", + "s_di", + FL_NOP | FL_SOURCE_DDL, + S_DIVISION_START, + S_DIVISION_END, + S_DIVISION, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_inventory", + "s_in", + FL_SOURCE_DDL | FL_DATE_BASED, + S_INVENTORY_START, + S_INVENTORY_END, + S_INVENTORY, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x07, + NULL}, + {"s_item", + "s_it", + FL_SOURCE_DDL, + S_ITEM_START, + S_ITEM_END, + S_ITEM, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_manager", + "s_mg", + FL_NOP | FL_SOURCE_DDL, + S_MANAGER_START, + S_MANAGER_END, + S_MANAGER, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_manufacturer", + "s_mn", + FL_NOP | FL_SOURCE_DDL, + S_MANUFACTURER_START, + S_MANUFACTURER_END, + S_MANUFACTURER, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_market", + "s_mk", + FL_NOP | FL_SOURCE_DDL, + S_MARKET_START, + S_MARKET_END, + S_MARKET, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_product", + "s_pr", + FL_NOP | FL_SOURCE_DDL, + S_PRODUCT_START, + S_PRODUCT_END, + S_PRODUCT, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_promotion", + "s_pm", + FL_SOURCE_DDL | FL_PASSTHRU, + S_PROMOTION_START, + S_PROMOTION_END, + S_PROMOTION, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_purchase", + "s_pu", + FL_SOURCE_DDL | FL_PARENT | FL_DATE_BASED, + S_PURCHASE_START, + S_PURCHASE_END, + S_PURCHASE, + S_PURCHASE_LINEITEM, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_purchase_lineitem", + "s_pl", + FL_SOURCE_DDL | FL_CHILD | FL_PARENT, + S_PURCHASE_LINEITEM_START, + S_PURCHASE_LINEITEM_END, + S_PURCHASE_LINEITEM, + S_STORE_RETURNS, + NULL, + 0, + 0, + 0, + 0x0, + 0x07, + NULL}, + {"s_reason", + "s_re", + FL_NOP | FL_SOURCE_DDL, + S_REASON_START, + S_REASON_END, + S_REASON, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_store", + "s_st", + FL_SOURCE_DDL, + S_STORE_START, + S_STORE_END, + S_STORE, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_store_promotional_item", + "s_sp", + FL_NOP | FL_SOURCE_DDL, + S_STORE_PROMOTIONAL_ITEM_START, + S_STORE_PROMOTIONAL_ITEM_END, + S_STORE_PROMOTIONAL_ITEM, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_store_returns", + "s_sr", + FL_SOURCE_DDL | FL_CHILD, + S_STORE_RETURNS_START, + S_STORE_RETURNS_END, + S_STORE_RETURNS, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0E, + NULL}, + {"s_subcategory", + "s_ct", + FL_NOP | FL_SOURCE_DDL, + S_SUBCATEGORY_START, + S_SUBCATEGORY_END, + S_SUBCATEGORY, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_subclass", + "s_sc", + FL_NOP | FL_SOURCE_DDL, + S_SUBCLASS_START, + S_SUBCLASS_END, + S_SUBCLASS, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_warehouse", + "s_.h", + FL_SOURCE_DDL, + S_WAREHOUSE_START, + S_WAREHOUSE_END, + S_WAREHOUSE, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_web_order", + "s_wo", + FL_SOURCE_DDL | FL_PARENT | FL_DATE_BASED, + S_WEB_ORDER_START, + S_WEB_ORDER_END, + S_WEB_ORDER, + S_WEB_ORDER_LINEITEM, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_web_order_lineitem", + "s_wl", + FL_SOURCE_DDL | FL_CHILD | FL_PARENT, + S_WEB_ORDER_LINEITEM_START, + S_WEB_ORDER_LINEITEM_END, + S_WEB_ORDER_LINEITEM, + S_WEB_RETURNS, + NULL, + 0, + 0, + 0, + 0x0, + 0x07, + NULL}, + {"s_web_page", + "s_wp", + FL_SOURCE_DDL | FL_PASSTHRU, + S_WEB_PAGE_START, + S_WEB_PAGE_END, + S_WEB_PAGE, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_web_promotional_item", + "s_wi", + FL_NOP | FL_SOURCE_DDL, + S_WEB_PROMOTIONAL_ITEM_START, + S_WEB_PROMOTIONAL_ITEM_END, + S_WEB_PROMOTIONAL_ITEM, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0, + NULL}, + {"s_web_returns", + "s_wr", + FL_SOURCE_DDL | FL_CHILD, + S_WEB_RETURNS_START, + S_WEB_RETURNS_END, + S_WEB_RETURNS, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x0E, + NULL}, + {"s_web_site", + "s_ws", + FL_SOURCE_DDL, + S_WEB_SITE_START, + S_WEB_SITE_END, + S_WEB_SITE, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x01, + NULL}, + {"s_zip_to_gmt", + "s_zi", + FL_SOURCE_DDL | FL_VPRINT, + S_ZIPG_START, + S_ZIPG_END, + S_ZIPG, + -1, + NULL, + 0, + 0, + 0, + 0x0, + 0x03, + NULL}, + {NULL}}; + + tdef w_tdefs[26] = { + {"call_center", + "cc", + FL_TYPE_2 | FL_SMALL, + CALL_CENTER_START, + CALL_CENTER_END, + CALL_CENTER, + -1, + NULL, + 0, + 0, + 100, + 0, + 0x0B, + NULL}, + {"catalog_page", + "cp", + 0, + CATALOG_PAGE_START, + CATALOG_PAGE_END, + CATALOG_PAGE, + -1, + NULL, + 0, + 0, + 200, + 0, + 0x03, + NULL}, + {"catalog_returns", + "cr", + FL_CHILD, + CATALOG_RETURNS_START, + CATALOG_RETURNS_END, + CATALOG_RETURNS, + -1, + NULL, + 0, + 0, + 400, + 0, + 0x10007, + NULL}, + {"catalog_sales", + "cs", + FL_PARENT | FL_DATE_BASED | FL_VPRINT, + CATALOG_SALES_START, + CATALOG_SALES_END, + CATALOG_SALES, + CATALOG_RETURNS, + NULL, + 0, + 0, + 100, + 0, + 0x28000, + NULL}, + {"customer", + "cu", + 0, + CUSTOMER_START, + CUSTOMER_END, + CUSTOMER, + -1, + NULL, + 0, + 0, + 700, + 0, + 0x13, + NULL}, + {"customer_address", + "ca", + 0, + CUSTOMER_ADDRESS_START, + CUSTOMER_ADDRESS_END, + CUSTOMER_ADDRESS, + -1, + NULL, + 0, + 0, + 600, + 0, + 0x03, + NULL}, + {"customer_demographics", + "cd", + 0, + CUSTOMER_DEMOGRAPHICS_START, + CUSTOMER_DEMOGRAPHICS_END, + CUSTOMER_DEMOGRAPHICS, + 823200, + NULL, + 0, + 0, + 0, + 0, + 0x1, + NULL}, + {"date_dim", + "da", + 0, + DATE_START, + DATE_END, + DATET, + -1, + NULL, + 0, + 0, + 0, + 0, + 0x03, + NULL}, + {"household_demographics", + "hd", + 0, + HOUSEHOLD_DEMOGRAPHICS_START, + HOUSEHOLD_DEMOGRAPHICS_END, + HOUSEHOLD_DEMOGRAPHICS, + 7200, + NULL, + 0, + 0, + 0, + 0, + 0x01, + NULL}, + {"income_band", + "ib", + 0, + INCOME_BAND_START, + INCOME_BAND_END, + INCOME_BAND, + -1, + NULL, + 0, + 0, + 0, + 0, + 0x1, + NULL}, + {"inventory", + "inv", + FL_DATE_BASED, + INVENTORY_START, + INVENTORY_END, + INVENTORY, + -1, + NULL, + 0, + 0, + 1000, + 0, + 0x07, + NULL}, + {"item", + "it", + FL_TYPE_2, + ITEM_START, + ITEM_END, + ITEM, + -1, + NULL, + 0, + 0, + 50, + 0, + 0x0B, + NULL}, + {"promotion", + "pr", + 0, + PROMOTION_START, + PROMOTION_END, + PROMOTION, + -1, + NULL, + 0, + 0, + 200, + 0, + 0x03, + NULL}, + {"reason", + "re", + 0, + REASON_START, + REASON_END, + REASON, + -1, + NULL, + 0, + 0, + 0, + 0, + 0x03, + NULL}, + {"ship_mode", + "sm", + 0, + SHIP_MODE_START, + SHIP_MODE_END, + SHIP_MODE, + -1, + NULL, + 0, + 0, + 0, + 0, + 0x03, + NULL}, + {"store", + "st", + FL_TYPE_2 | FL_SMALL, + STORE_START, + STORE_END, + STORE, + -1, + NULL, + 0, + 0, + 100, + 0, + 0xB, + NULL}, + {"store_returns", + "sr", + FL_CHILD, + STORE_RETURNS_START, + STORE_RETURNS_END, + STORE_RETURNS, + -1, + NULL, + 0, + 0, + 700, + 0, + 0x204, + NULL}, + {"store_sales", + "ss", + FL_PARENT | FL_DATE_BASED | FL_VPRINT, + STORE_SALES_START, + STORE_SALES_END, + STORE_SALES, + STORE_RETURNS, + NULL, + 0, + 0, + 900, + 0, + 0x204, + NULL}, + {"time_dim", + "ti", + 0, + TIME_START, + TIME_END, + TIME, + -1, + NULL, + 0, + 0, + 0, + 0, + 0x03, + NULL}, + {"warehouse", + "wa", + FL_SMALL, + WAREHOUSE_START, + WAREHOUSE_END, + WAREHOUSE, + -1, + NULL, + 0, + 0, + 200, + 0, + 0x03, + NULL}, + {"web_page", + "wp", + FL_TYPE_2, + WEB_PAGE_START, + WEB_PAGE_END, + WEB_PAGE, + -1, + NULL, + 0, + 0, + 250, + 0, + 0x0B, + NULL}, + {"web_returns", + "wr", + FL_CHILD, + WEB_RETURNS_START, + WEB_RETURNS_END, + WEB_RETURNS, + -1, + NULL, + 0, + 0, + 900, + 0, + 0x2004, + NULL}, + {"web_sales", + "ws", + FL_VPRINT | FL_PARENT | FL_DATE_BASED, + WEB_SALES_START, + WEB_SALES_END, + WEB_SALES, + WEB_RETURNS, + NULL, + 0, + 0, + 5, + 1100, + 0x20008, + NULL}, + {"web_site", + "web", + FL_TYPE_2 | FL_SMALL, + WEB_SITE_START, + WEB_SITE_END, + WEB_SITE, + -1, + NULL, + 0, + 0, + 100, + 0, + 0x0B, + NULL}, + {"dbgen_version", + "dv", + 0, + DBGEN_VERSION_START, + DBGEN_VERSION_END, + DBGEN_VERSION, + -1, + NULL, + 0, + 0, + 0, + 0, + 0, + NULL}, + {NULL}}; + + rng_t Streams[MAX_STREAM + 1] = { + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, CC_CALL_CENTER_SK, CALL_CENTER, CC_CALL_CENTER_SK, 0}, + {0, 15, 0, 0, CC_CALL_CENTER_ID, CALL_CENTER, CC_CALL_CENTER_ID, 0}, + {0, 10, 0, 0, CC_REC_START_DATE_ID, CALL_CENTER, CC_REC_START_DATE_ID, 0}, + {0, 1, 0, 0, CC_REC_END_DATE_ID, CALL_CENTER, CC_REC_END_DATE_ID, 0}, + {0, 4, 0, 0, CC_CLOSED_DATE_ID, CALL_CENTER, CC_CLOSED_DATE_ID, 0}, + {0, 10, 0, 0, CC_OPEN_DATE_ID, CALL_CENTER, CC_OPEN_DATE_ID, 0}, + {0, 0, 0, 0, CC_NAME, CALL_CENTER, CC_NAME, 0}, + {0, 2, 0, 0, CC_CLASS, CALL_CENTER, CC_CLASS, 0}, + {0, 1, 0, 0, CC_EMPLOYEES, CALL_CENTER, CC_EMPLOYEES, 0}, + {0, 1, 0, 0, CC_SQ_FT, CALL_CENTER, CC_SQ_FT, 0}, + {0, 1, 0, 0, CC_HOURS, CALL_CENTER, CC_HOURS, 0}, + {0, 2, 0, 0, CC_MANAGER, CALL_CENTER, CC_MANAGER, 0}, + {0, 1, 0, 0, CC_MARKET_ID, CALL_CENTER, CC_MARKET_ID, 0}, + {0, 50, 0, 0, CC_MARKET_CLASS, CALL_CENTER, CC_MARKET_CLASS, 0}, + {0, 50, 0, 0, CC_MARKET_DESC, CALL_CENTER, CC_MARKET_DESC, 0}, + {0, 2, 0, 0, CC_MARKET_MANAGER, CALL_CENTER, CC_MARKET_MANAGER, 0}, + {0, 2, 0, 0, CC_DIVISION, CALL_CENTER, CC_DIVISION, 0}, + {0, 2, 0, 0, CC_DIVISION_NAME, CALL_CENTER, CC_DIVISION_NAME, 0}, + {0, 2, 0, 0, CC_COMPANY, CALL_CENTER, CC_COMPANY, 0}, + {0, 2, 0, 0, CC_COMPANY_NAME, CALL_CENTER, CC_COMPANY_NAME, 0}, + {0, 0, 0, 0, CC_STREET_NUMBER, CALL_CENTER, CC_STREET_NUMBER, 0}, + {0, 0, 0, 0, CC_STREET_NAME, CALL_CENTER, CC_STREET_NAME, 0}, + {0, 0, 0, 0, CC_STREET_TYPE, CALL_CENTER, CC_STREET_TYPE, 0}, + {0, 0, 0, 0, CC_SUITE_NUMBER, CALL_CENTER, CC_SUITE_NUMBER, 0}, + {0, 0, 0, 0, CC_CITY, CALL_CENTER, CC_CITY, 0}, + {0, 0, 0, 0, CC_COUNTY, CALL_CENTER, CC_COUNTY, 0}, + {0, 0, 0, 0, CC_STATE, CALL_CENTER, CC_STATE, 0}, + {0, 0, 0, 0, CC_ZIP, CALL_CENTER, CC_ZIP, 0}, + {0, 0, 0, 0, CC_COUNTRY, CALL_CENTER, CC_COUNTRY, 0}, + {0, 0, 0, 0, CC_GMT_OFFSET, CALL_CENTER, CC_GMT_OFFSET, 0}, + {0, 15, 0, 0, CC_ADDRESS, CALL_CENTER, CC_ADDRESS, 0}, + {0, 1, 0, 0, CC_TAX_PERCENTAGE, CALL_CENTER, CC_TAX_PERCENTAGE, 0}, + {0, 1, 0, 0, CC_SCD, CALL_CENTER, CC_SCD, 0}, + {0, 2, 0, 0, CC_NULLS, CALL_CENTER, CC_NULLS, 0}, + {0, 1, 0, 0, CP_CATALOG_PAGE_SK, CATALOG_PAGE, CP_CATALOG_PAGE_SK, 0}, + {0, 1, 0, 0, CP_CATALOG_PAGE_ID, CATALOG_PAGE, CP_CATALOG_PAGE_ID, 0}, + {0, 1, 0, 0, CP_START_DATE_ID, CATALOG_PAGE, CP_START_DATE_ID, 0}, + {0, 1, 0, 0, CP_END_DATE_ID, CATALOG_PAGE, CP_END_DATE_ID, 0}, + {0, 1, 0, 0, CP_PROMO_ID, CATALOG_PAGE, CP_PROMO_ID, 0}, + {0, 1, 0, 0, CP_DEPARTMENT, CATALOG_PAGE, CP_DEPARTMENT, 0}, + {0, 1, 0, 0, CP_CATALOG_NUMBER, CATALOG_PAGE, CP_CATALOG_NUMBER, 0}, + {0, + 1, + 0, + 0, + CP_CATALOG_PAGE_NUMBER, + CATALOG_PAGE, + CP_CATALOG_PAGE_NUMBER, + 0}, + {0, 100, 0, 0, CP_DESCRIPTION, CATALOG_PAGE, S_CP_DESCRIPTION, 0}, + {0, 1, 0, 0, CP_TYPE, CATALOG_PAGE, CP_TYPE, 0}, + {0, 2, 0, 0, CP_NULLS, CATALOG_PAGE, CP_NULLS, 0}, + {0, + 28, + 0, + 0, + CR_RETURNED_DATE_SK, + CATALOG_RETURNS, + CR_RETURNED_DATE_SK, + 0}, + {0, + 28, + 0, + 0, + CR_RETURNED_TIME_SK, + CATALOG_RETURNS, + CR_RETURNED_TIME_SK, + 0}, + {0, 14, 0, 0, CR_ITEM_SK, CATALOG_RETURNS, CR_ITEM_SK, 0}, + {0, + 14, + 0, + 0, + CR_REFUNDED_CUSTOMER_SK, + CATALOG_RETURNS, + CR_REFUNDED_CUSTOMER_SK, + 0}, + {0, + 14, + 0, + 0, + CR_REFUNDED_CDEMO_SK, + CATALOG_RETURNS, + CR_REFUNDED_CDEMO_SK, + 0}, + {0, + 14, + 0, + 0, + CR_REFUNDED_HDEMO_SK, + CATALOG_RETURNS, + CR_REFUNDED_HDEMO_SK, + 0}, + {0, + 14, + 0, + 0, + CR_REFUNDED_ADDR_SK, + CATALOG_RETURNS, + CR_REFUNDED_ADDR_SK, + 0}, + {0, + 28, + 0, + 0, + CR_RETURNING_CUSTOMER_SK, + CATALOG_RETURNS, + CR_RETURNING_CUSTOMER_SK, + 0}, + {0, + 14, + 0, + 0, + CR_RETURNING_CDEMO_SK, + CATALOG_RETURNS, + CR_RETURNING_CDEMO_SK, + 0}, + {0, + 14, + 0, + 0, + CR_RETURNING_HDEMO_SK, + CATALOG_RETURNS, + CR_RETURNING_HDEMO_SK, + 0}, + {0, + 14, + 0, + 0, + CR_RETURNING_ADDR_SK, + CATALOG_RETURNS, + CR_RETURNING_ADDR_SK, + 0}, + {0, 0, 0, 0, CR_CALL_CENTER_SK, CATALOG_RETURNS, CR_CALL_CENTER_SK, 0}, + {0, 14, 0, 0, CR_CATALOG_PAGE_SK, CATALOG_RETURNS, CR_CATALOG_PAGE_SK, 0}, + {0, 14, 0, 0, CR_SHIP_MODE_SK, CATALOG_RETURNS, CR_SHIP_MODE_SK, 0}, + {0, 14, 0, 0, CR_WAREHOUSE_SK, CATALOG_RETURNS, CR_WAREHOUSE_SK, 0}, + {0, 14, 0, 0, CR_REASON_SK, CATALOG_RETURNS, CR_REASON_SK, 0}, + {0, 0, 0, 0, CR_ORDER_NUMBER, CATALOG_RETURNS, CR_ORDER_NUMBER, 0}, + {0, + 0, + 0, + 0, + CR_PRICING_QUANTITY, + CATALOG_RETURNS, + CR_PRICING_QUANTITY, + 0}, + {0, + 0, + 0, + 0, + CR_PRICING_NET_PAID, + CATALOG_RETURNS, + CR_PRICING_NET_PAID, + 0}, + {0, 0, 0, 0, CR_PRICING_EXT_TAX, CATALOG_RETURNS, CR_PRICING_EXT_TAX, 0}, + {0, + 0, + 0, + 0, + CR_PRICING_NET_PAID_INC_TAX, + CATALOG_RETURNS, + CR_PRICING_NET_PAID_INC_TAX, + 0}, + {0, 0, 0, 0, CR_PRICING_FEE, CATALOG_RETURNS, CR_PRICING_FEE, 0}, + {0, + 0, + 0, + 0, + CR_PRICING_EXT_SHIP_COST, + CATALOG_RETURNS, + CR_PRICING_EXT_SHIP_COST, + 0}, + {0, + 0, + 0, + 0, + CR_PRICING_REFUNDED_CASH, + CATALOG_RETURNS, + CR_PRICING_REFUNDED_CASH, + 0}, + {0, + 0, + 0, + 0, + CR_PRICING_REVERSED_CHARGE, + CATALOG_RETURNS, + CR_PRICING_REVERSED_CHARGE, + 0}, + {0, + 0, + 0, + 0, + CR_PRICING_STORE_CREDIT, + CATALOG_RETURNS, + CR_PRICING_STORE_CREDIT, + 0}, + {0, + 0, + 0, + 0, + CR_PRICING_NET_LOSS, + CATALOG_RETURNS, + CR_PRICING_NET_LOSS, + 0}, + {0, 28, 0, 0, CR_NULLS, CATALOG_RETURNS, CR_NULLS, 0}, + {0, 70, 0, 0, CR_PRICING, CATALOG_RETURNS, CR_PRICING, 0}, + {0, 1, 0, 0, CS_SOLD_DATE_SK, CATALOG_SALES, CS_SOLD_DATE_SK, 0}, + {0, 2, 0, 0, CS_SOLD_TIME_SK, CATALOG_SALES, CS_SOLD_TIME_SK, 0}, + {0, 14, 0, 0, CS_SHIP_DATE_SK, CATALOG_SALES, CS_SHIP_DATE_SK, 0}, + {0, 1, 0, 0, CS_BILL_CUSTOMER_SK, CATALOG_SALES, CS_BILL_CUSTOMER_SK, 0}, + {0, 1, 0, 0, CS_BILL_CDEMO_SK, CATALOG_SALES, CS_BILL_CDEMO_SK, 0}, + {0, 1, 0, 0, CS_BILL_HDEMO_SK, CATALOG_SALES, CS_BILL_HDEMO_SK, 0}, + {0, 1, 0, 0, CS_BILL_ADDR_SK, CATALOG_SALES, CS_BILL_ADDR_SK, 0}, + {0, 2, 0, 0, CS_SHIP_CUSTOMER_SK, CATALOG_SALES, CS_SHIP_CUSTOMER_SK, 0}, + {0, 1, 0, 0, CS_SHIP_CDEMO_SK, CATALOG_SALES, CS_SHIP_CDEMO_SK, 0}, + {0, 1, 0, 0, CS_SHIP_HDEMO_SK, CATALOG_SALES, CS_SHIP_HDEMO_SK, 0}, + {0, 1, 0, 0, CS_SHIP_ADDR_SK, CATALOG_SALES, CS_SHIP_ADDR_SK, 0}, + {0, 1, 0, 0, CS_CALL_CENTER_SK, CATALOG_SALES, CS_CALL_CENTER_SK, 0}, + {0, 42, 0, 0, CS_CATALOG_PAGE_SK, CATALOG_SALES, CS_CATALOG_PAGE_SK, 0}, + {0, 14, 0, 0, CS_SHIP_MODE_SK, CATALOG_SALES, CS_SHIP_MODE_SK, 0}, + {0, 14, 0, 0, CS_WAREHOUSE_SK, CATALOG_SALES, CS_WAREHOUSE_SK, 0}, + {0, 1, 0, 0, CS_SOLD_ITEM_SK, CATALOG_SALES, CS_SOLD_ITEM_SK, 0}, + {0, 14, 0, 0, CS_PROMO_SK, CATALOG_SALES, CS_PROMO_SK, 0}, + {0, 1, 0, 0, CS_ORDER_NUMBER, CATALOG_SALES, CS_ORDER_NUMBER, 0}, + {0, 0, 0, 0, CS_PRICING_QUANTITY, CATALOG_SALES, CS_PRICING_QUANTITY, 0}, + {0, + 0, + 0, + 0, + CS_PRICING_WHOLESALE_COST, + CATALOG_SALES, + CS_PRICING_WHOLESALE_COST, + 0}, + {0, + 0, + 0, + 0, + CS_PRICING_LIST_PRICE, + CATALOG_SALES, + CS_PRICING_LIST_PRICE, + 0}, + {0, + 0, + 0, + 0, + CS_PRICING_SALES_PRICE, + CATALOG_SALES, + CS_PRICING_SALES_PRICE, + 0}, + {0, + 0, + 0, + 0, + CS_PRICING_COUPON_AMT, + CATALOG_SALES, + CS_PRICING_COUPON_AMT, + 0}, + {0, + 0, + 0, + 0, + CS_PRICING_EXT_SALES_PRICE, + CATALOG_SALES, + CS_PRICING_EXT_SALES_PRICE, + 0}, + {0, + 0, + 0, + 0, + CS_PRICING_EXT_DISCOUNT_AMOUNT, + CATALOG_SALES, + CS_PRICING_EXT_DISCOUNT_AMOUNT, + 0}, + {0, + 0, + 0, + 0, + CS_PRICING_EXT_WHOLESALE_COST, + CATALOG_SALES, + CS_PRICING_EXT_WHOLESALE_COST, + 0}, + {0, + 0, + 0, + 0, + CS_PRICING_EXT_LIST_PRICE, + CATALOG_SALES, + CS_PRICING_EXT_LIST_PRICE, + 0}, + {0, 0, 0, 0, CS_PRICING_EXT_TAX, CATALOG_SALES, CS_PRICING_EXT_TAX, 0}, + {0, + 0, + 0, + 0, + CS_PRICING_EXT_SHIP_COST, + CATALOG_SALES, + CS_PRICING_EXT_SHIP_COST, + 0}, + {0, 0, 0, 0, CS_PRICING_NET_PAID, CATALOG_SALES, CS_PRICING_NET_PAID, 0}, + {0, + 0, + 0, + 0, + CS_PRICING_NET_PAID_INC_TAX, + CATALOG_SALES, + CS_PRICING_NET_PAID_INC_TAX, + 0}, + {0, + 0, + 0, + 0, + CS_PRICING_NET_PAID_INC_SHIP, + CATALOG_SALES, + CS_PRICING_NET_PAID_INC_SHIP, + 0}, + {0, + 0, + 0, + 0, + CS_PRICING_NET_PAID_INC_SHIP_TAX, + CATALOG_SALES, + CS_PRICING_NET_PAID_INC_SHIP_TAX, + 0}, + {0, + 0, + 0, + 0, + CS_PRICING_NET_PROFIT, + CATALOG_SALES, + CS_PRICING_NET_PROFIT, + 0}, + {0, 112, 0, 0, CS_PRICING, CATALOG_SALES, CS_PRICING, 0}, + {0, 0, 0, 0, CS_PERMUTE, CATALOG_SALES, CS_PERMUTE, 0}, + {0, 28, 0, 0, CS_NULLS, CATALOG_SALES, CS_NULLS, 0}, + {0, 14, 0, 0, CR_IS_RETURNED, CATALOG_SALES, CR_IS_RETURNED, 0}, + {0, 0, 0, 0, CS_PERMUTATION, CATALOG_SALES, CS_PERMUTATION, 0}, + {0, 1, 0, 0, C_CUSTOMER_SK, CUSTOMER, C_CUSTOMER_SK, 0}, + {0, 1, 0, 0, C_CUSTOMER_ID, CUSTOMER, C_CUSTOMER_ID, 0}, + {0, 1, 0, 0, C_CURRENT_CDEMO_SK, CUSTOMER, C_CURRENT_CDEMO_SK, 0}, + {0, 1, 0, 0, C_CURRENT_HDEMO_SK, CUSTOMER, C_CURRENT_HDEMO_SK, 0}, + {0, 1, 0, 0, C_CURRENT_ADDR_SK, CUSTOMER, C_CURRENT_ADDR_SK, 0}, + {0, 0, 0, 0, C_FIRST_SHIPTO_DATE_ID, CUSTOMER, C_FIRST_SHIPTO_DATE_ID, 0}, + {0, 1, 0, 0, C_FIRST_SALES_DATE_ID, CUSTOMER, C_FIRST_SALES_DATE_ID, 0}, + {0, 1, 0, 0, C_SALUTATION, CUSTOMER, C_SALUTATION, 0}, + {0, 1, 0, 0, C_FIRST_NAME, CUSTOMER, C_FIRST_NAME, 0}, + {0, 1, 0, 0, C_LAST_NAME, CUSTOMER, C_LAST_NAME, 0}, + {0, 2, 0, 0, C_PREFERRED_CUST_FLAG, CUSTOMER, C_PREFERRED_CUST_FLAG, 0}, + {0, 1, 0, 0, C_BIRTH_DAY, CUSTOMER, C_BIRTH_DAY, 0}, + {0, 0, 0, 0, C_BIRTH_MONTH, CUSTOMER, C_BIRTH_MONTH, 0}, + {0, 0, 0, 0, C_BIRTH_YEAR, CUSTOMER, C_BIRTH_YEAR, 0}, + {0, 1, 0, 0, C_BIRTH_COUNTRY, CUSTOMER, C_BIRTH_COUNTRY, 0}, + {0, 1, 0, 0, C_LOGIN, CUSTOMER, C_LOGIN, 0}, + {0, 23, 0, 0, C_EMAIL_ADDRESS, CUSTOMER, C_EMAIL_ADDRESS, 0}, + {0, 1, 0, 0, C_LAST_REVIEW_DATE, CUSTOMER, C_LAST_REVIEW_DATE, 0}, + {0, 2, 0, 0, C_NULLS, CUSTOMER, C_NULLS, 0}, + {0, 1, 0, 0, CA_ADDRESS_SK, CUSTOMER_ADDRESS, CA_ADDRESS_SK, 0}, + {0, 1, 0, 0, CA_ADDRESS_ID, CUSTOMER_ADDRESS, CA_ADDRESS_ID, 0}, + {0, + 1, + 0, + 0, + CA_ADDRESS_STREET_NUM, + CUSTOMER_ADDRESS, + CA_ADDRESS_STREET_NUM, + 0}, + {0, + 1, + 0, + 0, + CA_ADDRESS_STREET_NAME1, + CUSTOMER_ADDRESS, + CA_ADDRESS_STREET_NAME1, + 0}, + {0, + 1, + 0, + 0, + CA_ADDRESS_STREET_TYPE, + CUSTOMER_ADDRESS, + CA_ADDRESS_STREET_TYPE, + 0}, + {0, + 1, + 0, + 0, + CA_ADDRESS_SUITE_NUM, + CUSTOMER_ADDRESS, + CA_ADDRESS_SUITE_NUM, + 0}, + {0, 1, 0, 0, CA_ADDRESS_CITY, CUSTOMER_ADDRESS, CA_ADDRESS_CITY, 0}, + {0, 1, 0, 0, CA_ADDRESS_COUNTY, CUSTOMER_ADDRESS, CA_ADDRESS_COUNTY, 0}, + {0, 1, 0, 0, CA_ADDRESS_STATE, CUSTOMER_ADDRESS, CA_ADDRESS_STATE, 0}, + {0, 1, 0, 0, CA_ADDRESS_ZIP, CUSTOMER_ADDRESS, CA_ADDRESS_ZIP, 0}, + {0, 1, 0, 0, CA_ADDRESS_COUNTRY, CUSTOMER_ADDRESS, CA_ADDRESS_COUNTRY, 0}, + {0, + 1, + 0, + 0, + CA_ADDRESS_GMT_OFFSET, + CUSTOMER_ADDRESS, + CA_ADDRESS_GMT_OFFSET, + 0}, + {0, 1, 0, 0, CA_LOCATION_TYPE, CUSTOMER_ADDRESS, CA_LOCATION_TYPE, 0}, + {0, 2, 0, 0, CA_NULLS, CUSTOMER_ADDRESS, CA_NULLS, 0}, + {0, 7, 0, 0, CA_ADDRESS, CUSTOMER_ADDRESS, CA_ADDRESS, 0}, + {0, + 1, + 0, + 0, + CA_ADDRESS_STREET_NAME2, + CUSTOMER_ADDRESS, + CA_ADDRESS_STREET_NAME2, + 0}, + {0, 1, 0, 0, CD_DEMO_SK, CUSTOMER_DEMOGRAPHICS, CD_DEMO_SK, 0}, + {0, 1, 0, 0, CD_GENDER, CUSTOMER_DEMOGRAPHICS, CD_GENDER, 0}, + {0, + 1, + 0, + 0, + CD_MARITAL_STATUS, + CUSTOMER_DEMOGRAPHICS, + CD_MARITAL_STATUS, + 0}, + {0, + 1, + 0, + 0, + CD_EDUCATION_STATUS, + CUSTOMER_DEMOGRAPHICS, + CD_EDUCATION_STATUS, + 0}, + {0, + 1, + 0, + 0, + CD_PURCHASE_ESTIMATE, + CUSTOMER_DEMOGRAPHICS, + CD_PURCHASE_ESTIMATE, + 0}, + {0, + 1, + 0, + 0, + CD_CREDIT_RATING, + CUSTOMER_DEMOGRAPHICS, + CD_CREDIT_RATING, + 0}, + {0, 1, 0, 0, CD_DEP_COUNT, CUSTOMER_DEMOGRAPHICS, CD_DEP_COUNT, 0}, + {0, + 1, + 0, + 0, + CD_DEP_EMPLOYED_COUNT, + CUSTOMER_DEMOGRAPHICS, + CD_DEP_EMPLOYED_COUNT, + 0}, + {0, + 1, + 0, + 0, + CD_DEP_COLLEGE_COUNT, + CUSTOMER_DEMOGRAPHICS, + CD_DEP_COLLEGE_COUNT, + 0}, + {0, 2, 0, 0, CD_NULLS, CUSTOMER_DEMOGRAPHICS, CD_NULLS, 0}, + {0, 0, 0, 0, D_DATE_SK, DATET, D_DATE_SK, 0}, + {0, 0, 0, 0, D_DATE_ID, DATET, D_DATE_ID, 0}, + {0, 0, 0, 0, D_DATE, DATET, D_DATE, 0}, + {0, 0, 0, 0, D_MONTH_SEQ, DATET, D_MONTH_SEQ, 0}, + {0, 0, 0, 0, D_WEEK_SEQ, DATET, D_WEEK_SEQ, 0}, + {0, 0, 0, 0, D_QUARTER_SEQ, DATET, D_QUARTER_SEQ, 0}, + {0, 0, 0, 0, D_YEAR, DATET, D_YEAR, 0}, + {0, 0, 0, 0, D_DOW, DATET, D_DOW, 0}, + {0, 0, 0, 0, D_MOY, DATET, D_MOY, 0}, + {0, 0, 0, 0, D_DOM, DATET, D_DOM, 0}, + {0, 0, 0, 0, D_QOY, DATET, D_QOY, 0}, + {0, 0, 0, 0, D_FY_YEAR, DATET, D_FY_YEAR, 0}, + {0, 0, 0, 0, D_FY_QUARTER_SEQ, DATET, D_FY_QUARTER_SEQ, 0}, + {0, 0, 0, 0, D_FY_WEEK_SEQ, DATET, D_FY_WEEK_SEQ, 0}, + {0, 0, 0, 0, D_DAY_NAME, DATET, D_DAY_NAME, 0}, + {0, 0, 0, 0, D_QUARTER_NAME, DATET, D_QUARTER_NAME, 0}, + {0, 0, 0, 0, D_HOLIDAY, DATET, D_HOLIDAY, 0}, + {0, 0, 0, 0, D_WEEKEND, DATET, D_WEEKEND, 0}, + {0, 0, 0, 0, D_FOLLOWING_HOLIDAY, DATET, D_FOLLOWING_HOLIDAY, 0}, + {0, 0, 0, 0, D_FIRST_DOM, DATET, D_FIRST_DOM, 0}, + {0, 0, 0, 0, D_LAST_DOM, DATET, D_LAST_DOM, 0}, + {0, 0, 0, 0, D_SAME_DAY_LY, DATET, D_SAME_DAY_LY, 0}, + {0, 0, 0, 0, D_SAME_DAY_LQ, DATET, D_SAME_DAY_LQ, 0}, + {0, 0, 0, 0, D_CURRENT_DAY, DATET, D_CURRENT_DAY, 0}, + {0, 0, 0, 0, D_CURRENT_WEEK, DATET, D_CURRENT_WEEK, 0}, + {0, 0, 0, 0, D_CURRENT_MONTH, DATET, D_CURRENT_MONTH, 0}, + {0, 0, 0, 0, D_CURRENT_QUARTER, DATET, D_CURRENT_QUARTER, 0}, + {0, 0, 0, 0, D_CURRENT_YEAR, DATET, D_CURRENT_YEAR, 0}, + {0, 2, 0, 0, D_NULLS, DATET, D_NULLS, 0}, + {0, 1, 0, 0, HD_DEMO_SK, HOUSEHOLD_DEMOGRAPHICS, HD_DEMO_SK, 0}, + {0, + 1, + 0, + 0, + HD_INCOME_BAND_ID, + HOUSEHOLD_DEMOGRAPHICS, + HD_INCOME_BAND_ID, + 0}, + {0, + 1, + 0, + 0, + HD_BUY_POTENTIAL, + HOUSEHOLD_DEMOGRAPHICS, + HD_BUY_POTENTIAL, + 0}, + {0, 1, 0, 0, HD_DEP_COUNT, HOUSEHOLD_DEMOGRAPHICS, HD_DEP_COUNT, 0}, + {0, + 1, + 0, + 0, + HD_VEHICLE_COUNT, + HOUSEHOLD_DEMOGRAPHICS, + HD_VEHICLE_COUNT, + 0}, + {0, 2, 0, 0, HD_NULLS, HOUSEHOLD_DEMOGRAPHICS, HD_NULLS, 0}, + {0, 1, 0, 0, IB_INCOME_BAND_ID, INCOME_BAND, IB_INCOME_BAND_ID, 0}, + {0, 1, 0, 0, IB_LOWER_BOUND, INCOME_BAND, IB_LOWER_BOUND, 0}, + {0, 1, 0, 0, IB_UPPER_BOUND, INCOME_BAND, IB_UPPER_BOUND, 0}, + {0, 2, 0, 0, IB_NULLS, INCOME_BAND, IB_NULLS, 0}, + {0, 1, 0, 0, INV_DATE_SK, INVENTORY, INV_DATE_SK, 0}, + {0, 1, 0, 0, INV_ITEM_SK, INVENTORY, INV_ITEM_SK, 0}, + {0, 1, 0, 0, INV_WAREHOUSE_SK, INVENTORY, INV_WAREHOUSE_SK, 0}, + {0, 1, 0, 0, INV_QUANTITY_ON_HAND, INVENTORY, INV_QUANTITY_ON_HAND, 0}, + {0, 2, 0, 0, INV_NULLS, INVENTORY, INV_NULLS, 0}, + {0, 1, 0, 0, I_ITEM_SK, ITEM, I_ITEM_SK, 0}, + {0, 1, 0, 0, I_ITEM_ID, ITEM, I_ITEM_ID, 0}, + {0, 1, 0, 0, I_REC_START_DATE_ID, ITEM, I_REC_START_DATE_ID, 0}, + {0, 2, 0, 0, I_REC_END_DATE_ID, ITEM, I_REC_END_DATE_ID, 0}, + {0, 200, 0, 0, I_ITEM_DESC, ITEM, S_ITEM_DESC, 0}, + {0, 2, 0, 0, I_CURRENT_PRICE, ITEM, I_CURRENT_PRICE, 0}, + {0, 1, 0, 0, I_WHOLESALE_COST, ITEM, I_WHOLESALE_COST, 0}, + {0, 1, 0, 0, I_BRAND_ID, ITEM, I_BRAND_ID, 0}, + {0, 1, 0, 0, I_BRAND, ITEM, I_BRAND, 0}, + {0, 1, 0, 0, I_CLASS_ID, ITEM, I_CLASS_ID, 0}, + {0, 1, 0, 0, I_CLASS, ITEM, I_CLASS, 0}, + {0, 1, 0, 0, I_CATEGORY_ID, ITEM, I_CATEGORY_ID, 0}, + {0, 1, 0, 0, I_CATEGORY, ITEM, I_CATEGORY, 0}, + {0, 2, 0, 0, I_MANUFACT_ID, ITEM, I_MANUFACT_ID, 0}, + {0, 1, 0, 0, I_MANUFACT, ITEM, I_MANUFACT, 0}, + {0, 1, 0, 0, I_SIZE, ITEM, I_SIZE, 0}, + {0, 50, 0, 0, I_FORMULATION, ITEM, I_FORMULATION, 0}, + {0, 1, 0, 0, I_COLOR, ITEM, I_COLOR, 0}, + {0, 1, 0, 0, I_UNITS, ITEM, I_UNITS, 0}, + {0, 1, 0, 0, I_CONTAINER, ITEM, I_CONTAINER, 0}, + {0, 2, 0, 0, I_MANAGER_ID, ITEM, I_MANAGER_ID, 0}, + {0, 1, 0, 0, I_PRODUCT_NAME, ITEM, I_PRODUCT_NAME, 0}, + {0, 2, 0, 0, I_NULLS, ITEM, I_NULLS, 0}, + {0, 1, 0, 0, I_SCD, ITEM, I_SCD, 0}, + {0, 2, 0, 0, I_PROMO_SK, ITEM, I_PROMO_SK, 0}, + {0, 1, 0, 0, P_PROMO_SK, PROMOTION, P_PROMO_SK, 0}, + {0, 1, 0, 0, P_PROMO_ID, PROMOTION, P_PROMO_ID, 0}, + {0, 1, 0, 0, P_START_DATE_ID, PROMOTION, P_START_DATE_ID, 0}, + {0, 1, 0, 0, P_END_DATE_ID, PROMOTION, P_END_DATE_ID, 0}, + {0, 1, 0, 0, P_ITEM_SK, PROMOTION, P_ITEM_SK, 0}, + {0, 1, 0, 0, P_COST, PROMOTION, P_COST, 0}, + {0, 1, 0, 0, P_RESPONSE_TARGET, PROMOTION, P_RESPONSE_TARGET, 0}, + {0, 1, 0, 0, P_PROMO_NAME, PROMOTION, P_PROMO_NAME, 0}, + {0, 1, 0, 0, P_CHANNEL_DMAIL, PROMOTION, P_CHANNEL_DMAIL, 0}, + {0, 1, 0, 0, P_CHANNEL_EMAIL, PROMOTION, P_CHANNEL_EMAIL, 0}, + {0, 1, 0, 0, P_CHANNEL_CATALOG, PROMOTION, P_CHANNEL_CATALOG, 0}, + {0, 1, 0, 0, P_CHANNEL_TV, PROMOTION, P_CHANNEL_TV, 0}, + {0, 1, 0, 0, P_CHANNEL_RADIO, PROMOTION, P_CHANNEL_RADIO, 0}, + {0, 1, 0, 0, P_CHANNEL_PRESS, PROMOTION, P_CHANNEL_PRESS, 0}, + {0, 1, 0, 0, P_CHANNEL_EVENT, PROMOTION, P_CHANNEL_EVENT, 0}, + {0, 1, 0, 0, P_CHANNEL_DEMO, PROMOTION, P_CHANNEL_DEMO, 0}, + {0, 100, 0, 0, P_CHANNEL_DETAILS, PROMOTION, P_CHANNEL_DETAILS, 0}, + {0, 1, 0, 0, P_PURPOSE, PROMOTION, P_PURPOSE, 0}, + {0, 1, 0, 0, P_DISCOUNT_ACTIVE, PROMOTION, P_DISCOUNT_ACTIVE, 0}, + {0, 2, 0, 0, P_NULLS, PROMOTION, P_NULLS, 0}, + {0, 1, 0, 0, R_REASON_SK, REASON, R_REASON_SK, 0}, + {0, 1, 0, 0, R_REASON_ID, REASON, R_REASON_ID, 0}, + {0, 1, 0, 0, R_REASON_DESCRIPTION, REASON, R_REASON_DESCRIPTION, 0}, + {0, 2, 0, 0, R_NULLS, REASON, R_NULLS, 0}, + {0, 1, 0, 0, SM_SHIP_MODE_SK, SHIP_MODE, SM_SHIP_MODE_SK, 0}, + {0, 1, 0, 0, SM_SHIP_MODE_ID, SHIP_MODE, SM_SHIP_MODE_ID, 0}, + {0, 1, 0, 0, SM_TYPE, SHIP_MODE, SM_TYPE, 0}, + {0, 1, 0, 0, SM_CODE, SHIP_MODE, SM_CODE, 0}, + {0, 21, 0, 0, SM_CONTRACT, SHIP_MODE, SM_CONTRACT, 0}, + {0, 1, 0, 0, SM_CARRIER, SHIP_MODE, SM_CARRIER, 0}, + {0, 2, 0, 0, SM_NULLS, SHIP_MODE, SM_NULLS, 0}, + {0, 1, 0, 0, W_STORE_SK, STORE, W_STORE_SK, 0}, + {0, 1, 0, 0, W_STORE_ID, STORE, W_STORE_ID, 0}, + {0, + 1, + 0, + 0, + W_STORE_REC_START_DATE_ID, + STORE, + W_STORE_REC_START_DATE_ID, + 0}, + {0, 2, 0, 0, W_STORE_REC_END_DATE_ID, STORE, W_STORE_REC_END_DATE_ID, 0}, + {0, 2, 0, 0, W_STORE_CLOSED_DATE_ID, STORE, W_STORE_CLOSED_DATE_ID, 0}, + {0, 0, 0, 0, W_STORE_NAME, STORE, W_STORE_NAME, 0}, + {0, 1, 0, 0, W_STORE_EMPLOYEES, STORE, W_STORE_EMPLOYEES, 0}, + {0, 1, 0, 0, W_STORE_FLOOR_SPACE, STORE, W_STORE_FLOOR_SPACE, 0}, + {0, 1, 0, 0, W_STORE_HOURS, STORE, W_STORE_HOURS, 0}, + {0, 2, 0, 0, W_STORE_MANAGER, STORE, W_STORE_MANAGER, 0}, + {0, 1, 0, 0, W_STORE_MARKET_ID, STORE, W_STORE_MARKET_ID, 0}, + {0, 1, 0, 0, W_STORE_TAX_PERCENTAGE, STORE, W_STORE_TAX_PERCENTAGE, 0}, + {0, 1, 0, 0, W_STORE_GEOGRAPHY_CLASS, STORE, W_STORE_GEOGRAPHY_CLASS, 0}, + {0, 100, 0, 0, W_STORE_MARKET_DESC, STORE, W_STORE_MARKET_DESC, 0}, + {0, 2, 0, 0, W_STORE_MARKET_MANAGER, STORE, W_STORE_MARKET_MANAGER, 0}, + {0, 1, 0, 0, W_STORE_DIVISION_ID, STORE, W_STORE_DIVISION_ID, 0}, + {0, 1, 0, 0, W_STORE_DIVISION_NAME, STORE, W_STORE_DIVISION_NAME, 0}, + {0, 1, 0, 0, W_STORE_COMPANY_ID, STORE, W_STORE_COMPANY_ID, 0}, + {0, 1, 0, 0, W_STORE_COMPANY_NAME, STORE, W_STORE_COMPANY_NAME, 0}, + {0, + 1, + 0, + 0, + W_STORE_ADDRESS_STREET_NUM, + STORE, + W_STORE_ADDRESS_STREET_NUM, + 0}, + {0, + 1, + 0, + 0, + W_STORE_ADDRESS_STREET_NAME1, + STORE, + W_STORE_ADDRESS_STREET_NAME1, + 0}, + {0, + 1, + 0, + 0, + W_STORE_ADDRESS_STREET_TYPE, + STORE, + W_STORE_ADDRESS_STREET_TYPE, + 0}, + {0, + 1, + 0, + 0, + W_STORE_ADDRESS_SUITE_NUM, + STORE, + W_STORE_ADDRESS_SUITE_NUM, + 0}, + {0, 1, 0, 0, W_STORE_ADDRESS_CITY, STORE, W_STORE_ADDRESS_CITY, 0}, + {0, 1, 0, 0, W_STORE_ADDRESS_COUNTY, STORE, W_STORE_ADDRESS_COUNTY, 0}, + {0, 1, 0, 0, W_STORE_ADDRESS_STATE, STORE, W_STORE_ADDRESS_STATE, 0}, + {0, 1, 0, 0, W_STORE_ADDRESS_ZIP, STORE, W_STORE_ADDRESS_ZIP, 0}, + {0, 1, 0, 0, W_STORE_ADDRESS_COUNTRY, STORE, W_STORE_ADDRESS_COUNTRY, 0}, + {0, + 1, + 0, + 0, + W_STORE_ADDRESS_GMT_OFFSET, + STORE, + W_STORE_ADDRESS_GMT_OFFSET, + 0}, + {0, 2, 0, 0, W_STORE_NULLS, STORE, W_STORE_NULLS, 0}, + {0, 1, 0, 0, W_STORE_TYPE, STORE, W_STORE_TYPE, 0}, + {0, 1, 0, 0, W_STORE_SCD, STORE, W_STORE_SCD, 0}, + {0, 7, 0, 0, W_STORE_ADDRESS, STORE, W_STORE_ADDRESS, 0}, + {0, 32, 0, 0, SR_RETURNED_DATE_SK, STORE_RETURNS, SR_RETURNED_DATE_SK, 0}, + {0, 32, 0, 0, SR_RETURNED_TIME_SK, STORE_RETURNS, SR_RETURNED_TIME_SK, 0}, + {0, 16, 0, 0, SR_ITEM_SK, STORE_RETURNS, SR_ITEM_SK, 0}, + {0, 16, 0, 0, SR_CUSTOMER_SK, STORE_RETURNS, SR_CUSTOMER_SK, 0}, + {0, 16, 0, 0, SR_CDEMO_SK, STORE_RETURNS, SR_CDEMO_SK, 0}, + {0, 16, 0, 0, SR_HDEMO_SK, STORE_RETURNS, SR_HDEMO_SK, 0}, + {0, 16, 0, 0, SR_ADDR_SK, STORE_RETURNS, SR_ADDR_SK, 0}, + {0, 16, 0, 0, SR_STORE_SK, STORE_RETURNS, SR_STORE_SK, 0}, + {0, 16, 0, 0, SR_REASON_SK, STORE_RETURNS, SR_REASON_SK, 0}, + {0, 16, 0, 0, SR_TICKET_NUMBER, STORE_RETURNS, SR_TICKET_NUMBER, 0}, + {0, 0, 0, 0, SR_PRICING_QUANTITY, STORE_RETURNS, SR_PRICING_QUANTITY, 0}, + {0, 0, 0, 0, SR_PRICING_NET_PAID, STORE_RETURNS, SR_PRICING_NET_PAID, 0}, + {0, 0, 0, 0, SR_PRICING_EXT_TAX, STORE_RETURNS, SR_PRICING_EXT_TAX, 0}, + {0, + 0, + 0, + 0, + SR_PRICING_NET_PAID_INC_TAX, + STORE_RETURNS, + SR_PRICING_NET_PAID_INC_TAX, + 0}, + {0, 0, 0, 0, SR_PRICING_FEE, STORE_RETURNS, SR_PRICING_FEE, 0}, + {0, + 0, + 0, + 0, + SR_PRICING_EXT_SHIP_COST, + STORE_RETURNS, + SR_PRICING_EXT_SHIP_COST, + 0}, + {0, + 0, + 0, + 0, + SR_PRICING_REFUNDED_CASH, + STORE_RETURNS, + SR_PRICING_REFUNDED_CASH, + 0}, + {0, + 0, + 0, + 0, + SR_PRICING_REVERSED_CHARGE, + STORE_RETURNS, + SR_PRICING_REVERSED_CHARGE, + 0}, + {0, + 0, + 0, + 0, + SR_PRICING_STORE_CREDIT, + STORE_RETURNS, + SR_PRICING_STORE_CREDIT, + 0}, + {0, 0, 0, 0, SR_PRICING_NET_LOSS, STORE_RETURNS, SR_PRICING_NET_LOSS, 0}, + {0, 80, 0, 0, SR_PRICING, STORE_RETURNS, SR_PRICING, 0}, + {0, 32, 0, 0, SR_NULLS, STORE_RETURNS, SR_NULLS, 0}, + {0, 2, 0, 0, SS_SOLD_DATE_SK, STORE_SALES, SS_SOLD_DATE_SK, 0}, + {0, 2, 0, 0, SS_SOLD_TIME_SK, STORE_SALES, SS_SOLD_TIME_SK, 0}, + {0, 1, 0, 0, SS_SOLD_ITEM_SK, STORE_SALES, SS_SOLD_ITEM_SK, 0}, + {0, 1, 0, 0, SS_SOLD_CUSTOMER_SK, STORE_SALES, SS_SOLD_CUSTOMER_SK, 0}, + {0, 1, 0, 0, SS_SOLD_CDEMO_SK, STORE_SALES, SS_SOLD_CDEMO_SK, 0}, + {0, 1, 0, 0, SS_SOLD_HDEMO_SK, STORE_SALES, SS_SOLD_HDEMO_SK, 0}, + {0, 1, 0, 0, SS_SOLD_ADDR_SK, STORE_SALES, SS_SOLD_ADDR_SK, 0}, + {0, 1, 0, 0, SS_SOLD_STORE_SK, STORE_SALES, SS_SOLD_STORE_SK, 0}, + {0, 16, 0, 0, SS_SOLD_PROMO_SK, STORE_SALES, SS_SOLD_PROMO_SK, 0}, + {0, 1, 0, 0, SS_TICKET_NUMBER, STORE_SALES, SS_TICKET_NUMBER, 0}, + {0, 1, 0, 0, SS_PRICING_QUANTITY, STORE_SALES, SS_PRICING_QUANTITY, 0}, + {0, + 0, + 0, + 0, + SS_PRICING_WHOLESALE_COST, + STORE_SALES, + SS_PRICING_WHOLESALE_COST, + 0}, + {0, + 0, + 0, + 0, + SS_PRICING_LIST_PRICE, + STORE_SALES, + SS_PRICING_LIST_PRICE, + 0}, + {0, + 0, + 0, + 0, + SS_PRICING_SALES_PRICE, + STORE_SALES, + SS_PRICING_SALES_PRICE, + 0}, + {0, + 0, + 0, + 0, + SS_PRICING_COUPON_AMT, + STORE_SALES, + SS_PRICING_COUPON_AMT, + 0}, + {0, + 0, + 0, + 0, + SS_PRICING_EXT_SALES_PRICE, + STORE_SALES, + SS_PRICING_EXT_SALES_PRICE, + 0}, + {0, + 0, + 0, + 0, + SS_PRICING_EXT_WHOLESALE_COST, + STORE_SALES, + SS_PRICING_EXT_WHOLESALE_COST, + 0}, + {0, + 0, + 0, + 0, + SS_PRICING_EXT_LIST_PRICE, + STORE_SALES, + SS_PRICING_EXT_LIST_PRICE, + 0}, + {0, 0, 0, 0, SS_PRICING_EXT_TAX, STORE_SALES, SS_PRICING_EXT_TAX, 0}, + {0, 0, 0, 0, SS_PRICING_NET_PAID, STORE_SALES, SS_PRICING_NET_PAID, 0}, + {0, + 0, + 0, + 0, + SS_PRICING_NET_PAID_INC_TAX, + STORE_SALES, + SS_PRICING_NET_PAID_INC_TAX, + 0}, + {0, + 0, + 0, + 0, + SS_PRICING_NET_PROFIT, + STORE_SALES, + SS_PRICING_NET_PROFIT, + 0}, + {0, 16, 0, 0, SR_IS_RETURNED, STORE_SALES, SR_IS_RETURNED, 0}, + {0, 128, 0, 0, SS_PRICING, STORE_SALES, SS_PRICING, 0}, + {0, 32, 0, 0, SS_NULLS, STORE_SALES, SS_NULLS, 0}, + {0, 0, 0, 0, SS_PERMUTATION, STORE_SALES, SS_PERMUTATION, 0}, + {0, 1, 0, 0, T_TIME_SK, TIME, T_TIME_SK, 0}, + {0, 1, 0, 0, T_TIME_ID, TIME, T_TIME_ID, 0}, + {0, 1, 0, 0, T_TIME, TIME, T_TIME, 0}, + {0, 1, 0, 0, T_HOUR, TIME, T_HOUR, 0}, + {0, 1, 0, 0, T_MINUTE, TIME, T_MINUTE, 0}, + {0, 1, 0, 0, T_SECOND, TIME, T_SECOND, 0}, + {0, 1, 0, 0, T_AM_PM, TIME, T_AM_PM, 0}, + {0, 1, 0, 0, T_SHIFT, TIME, T_SHIFT, 0}, + {0, 1, 0, 0, T_SUB_SHIFT, TIME, T_SUB_SHIFT, 0}, + {0, 1, 0, 0, T_MEAL_TIME, TIME, T_MEAL_TIME, 0}, + {0, 2, 0, 0, T_NULLS, TIME, T_NULLS, 0}, + {0, 1, 0, 0, W_WAREHOUSE_SK, WAREHOUSE, W_WAREHOUSE_SK, 0}, + {0, 1, 0, 0, W_WAREHOUSE_ID, WAREHOUSE, W_WAREHOUSE_ID, 0}, + {0, 80, 0, 0, W_WAREHOUSE_NAME, WAREHOUSE, W_WAREHOUSE_NAME, 0}, + {0, 1, 0, 0, W_WAREHOUSE_SQ_FT, WAREHOUSE, W_WAREHOUSE_SQ_FT, 0}, + {0, 1, 0, 0, W_ADDRESS_STREET_NUM, WAREHOUSE, W_ADDRESS_STREET_NUM, 0}, + {0, + 1, + 0, + 0, + W_ADDRESS_STREET_NAME1, + WAREHOUSE, + W_ADDRESS_STREET_NAME1, + 0}, + {0, 1, 0, 0, W_ADDRESS_STREET_TYPE, WAREHOUSE, W_ADDRESS_STREET_TYPE, 0}, + {0, 1, 0, 0, W_ADDRESS_SUITE_NUM, WAREHOUSE, W_ADDRESS_SUITE_NUM, 0}, + {0, 1, 0, 0, W_ADDRESS_CITY, WAREHOUSE, W_ADDRESS_CITY, 0}, + {0, 1, 0, 0, W_ADDRESS_COUNTY, WAREHOUSE, W_ADDRESS_COUNTY, 0}, + {0, 1, 0, 0, W_ADDRESS_STATE, WAREHOUSE, W_ADDRESS_STATE, 0}, + {0, 1, 0, 0, W_ADDRESS_ZIP, WAREHOUSE, W_ADDRESS_ZIP, 0}, + {0, 1, 0, 0, W_ADDRESS_COUNTRY, WAREHOUSE, W_ADDRESS_COUNTRY, 0}, + {0, 1, 0, 0, W_ADDRESS_GMT_OFFSET, WAREHOUSE, W_ADDRESS_GMT_OFFSET, 0}, + {0, 2, 0, 0, W_NULLS, WAREHOUSE, W_NULLS, 0}, + {0, 7, 0, 0, W_WAREHOUSE_ADDRESS, WAREHOUSE, W_WAREHOUSE_ADDRESS, 0}, + {0, 1, 0, 0, WP_PAGE_SK, WEB_PAGE, WP_PAGE_SK, 0}, + {0, 1, 0, 0, WP_PAGE_ID, WEB_PAGE, WP_PAGE_ID, 0}, + {0, 1, 0, 0, WP_REC_START_DATE_ID, WEB_PAGE, WP_REC_START_DATE_ID, 0}, + {0, 1, 0, 0, WP_REC_END_DATE_ID, WEB_PAGE, WP_REC_END_DATE_ID, 0}, + {0, 2, 0, 0, WP_CREATION_DATE_SK, WEB_PAGE, WP_CREATION_DATE_SK, 0}, + {0, 1, 0, 0, WP_ACCESS_DATE_SK, WEB_PAGE, WP_ACCESS_DATE_SK, 0}, + {0, 1, 0, 0, WP_AUTOGEN_FLAG, WEB_PAGE, WP_AUTOGEN_FLAG, 0}, + {0, 1, 0, 0, WP_CUSTOMER_SK, WEB_PAGE, WP_CUSTOMER_SK, 0}, + {0, 1, 0, 0, WP_URL, WEB_PAGE, WP_URL, 0}, + {0, 1, 0, 0, WP_TYPE, WEB_PAGE, WP_TYPE, 0}, + {0, 1, 0, 0, WP_CHAR_COUNT, WEB_PAGE, WP_CHAR_COUNT, 0}, + {0, 1, 0, 0, WP_LINK_COUNT, WEB_PAGE, WP_LINK_COUNT, 0}, + {0, 1, 0, 0, WP_IMAGE_COUNT, WEB_PAGE, WP_IMAGE_COUNT, 0}, + {0, 1, 0, 0, WP_MAX_AD_COUNT, WEB_PAGE, WP_MAX_AD_COUNT, 0}, + {0, 2, 0, 0, WP_NULLS, WEB_PAGE, WP_NULLS, 0}, + {0, 1, 0, 0, WP_SCD, WEB_PAGE, WP_SCD, 0}, + {0, 32, 0, 0, WR_RETURNED_DATE_SK, WEB_RETURNS, WR_RETURNED_DATE_SK, 0}, + {0, 32, 0, 0, WR_RETURNED_TIME_SK, WEB_RETURNS, WR_RETURNED_TIME_SK, 0}, + {0, 16, 0, 0, WR_ITEM_SK, WEB_RETURNS, WR_ITEM_SK, 0}, + {0, + 16, + 0, + 0, + WR_REFUNDED_CUSTOMER_SK, + WEB_RETURNS, + WR_REFUNDED_CUSTOMER_SK, + 0}, + {0, 16, 0, 0, WR_REFUNDED_CDEMO_SK, WEB_RETURNS, WR_REFUNDED_CDEMO_SK, 0}, + {0, 16, 0, 0, WR_REFUNDED_HDEMO_SK, WEB_RETURNS, WR_REFUNDED_HDEMO_SK, 0}, + {0, 16, 0, 0, WR_REFUNDED_ADDR_SK, WEB_RETURNS, WR_REFUNDED_ADDR_SK, 0}, + {0, + 16, + 0, + 0, + WR_RETURNING_CUSTOMER_SK, + WEB_RETURNS, + WR_RETURNING_CUSTOMER_SK, + 0}, + {0, + 16, + 0, + 0, + WR_RETURNING_CDEMO_SK, + WEB_RETURNS, + WR_RETURNING_CDEMO_SK, + 0}, + {0, + 16, + 0, + 0, + WR_RETURNING_HDEMO_SK, + WEB_RETURNS, + WR_RETURNING_HDEMO_SK, + 0}, + {0, 16, 0, 0, WR_RETURNING_ADDR_SK, WEB_RETURNS, WR_RETURNING_ADDR_SK, 0}, + {0, 16, 0, 0, WR_WEB_PAGE_SK, WEB_RETURNS, WR_WEB_PAGE_SK, 0}, + {0, 16, 0, 0, WR_REASON_SK, WEB_RETURNS, WR_REASON_SK, 0}, + {0, 0, 0, 0, WR_ORDER_NUMBER, WEB_RETURNS, WR_ORDER_NUMBER, 0}, + {0, 0, 0, 0, WR_PRICING_QUANTITY, WEB_RETURNS, WR_PRICING_QUANTITY, 0}, + {0, 0, 0, 0, WR_PRICING_NET_PAID, WEB_RETURNS, WR_PRICING_NET_PAID, 0}, + {0, 0, 0, 0, WR_PRICING_EXT_TAX, WEB_RETURNS, WR_PRICING_EXT_TAX, 0}, + {0, + 0, + 0, + 0, + WR_PRICING_NET_PAID_INC_TAX, + WEB_RETURNS, + WR_PRICING_NET_PAID_INC_TAX, + 0}, + {0, 0, 0, 0, WR_PRICING_FEE, WEB_RETURNS, WR_PRICING_FEE, 0}, + {0, + 0, + 0, + 0, + WR_PRICING_EXT_SHIP_COST, + WEB_RETURNS, + WR_PRICING_EXT_SHIP_COST, + 0}, + {0, + 0, + 0, + 0, + WR_PRICING_REFUNDED_CASH, + WEB_RETURNS, + WR_PRICING_REFUNDED_CASH, + 0}, + {0, + 0, + 0, + 0, + WR_PRICING_REVERSED_CHARGE, + WEB_RETURNS, + WR_PRICING_REVERSED_CHARGE, + 0}, + {0, + 0, + 0, + 0, + WR_PRICING_STORE_CREDIT, + WEB_RETURNS, + WR_PRICING_STORE_CREDIT, + 0}, + {0, 0, 0, 0, WR_PRICING_NET_LOSS, WEB_RETURNS, WR_PRICING_NET_LOSS, 0}, + {0, 80, 0, 0, WR_PRICING, WEB_RETURNS, WR_PRICING, 0}, + {0, 32, 0, 0, WR_NULLS, WEB_RETURNS, WR_NULLS, 0}, + {0, 2, 0, 0, WS_SOLD_DATE_SK, WEB_SALES, WS_SOLD_DATE_SK, 0}, + {0, 2, 0, 0, WS_SOLD_TIME_SK, WEB_SALES, WS_SOLD_TIME_SK, 0}, + {0, 16, 0, 0, WS_SHIP_DATE_SK, WEB_SALES, WS_SHIP_DATE_SK, 0}, + {0, 1, 0, 0, WS_ITEM_SK, WEB_SALES, WS_ITEM_SK, 0}, + {0, 1, 0, 0, WS_BILL_CUSTOMER_SK, WEB_SALES, WS_BILL_CUSTOMER_SK, 0}, + {0, 1, 0, 0, WS_BILL_CDEMO_SK, WEB_SALES, WS_BILL_CDEMO_SK, 0}, + {0, 1, 0, 0, WS_BILL_HDEMO_SK, WEB_SALES, WS_BILL_HDEMO_SK, 0}, + {0, 1, 0, 0, WS_BILL_ADDR_SK, WEB_SALES, WS_BILL_ADDR_SK, 0}, + {0, 2, 0, 0, WS_SHIP_CUSTOMER_SK, WEB_SALES, WS_SHIP_CUSTOMER_SK, 0}, + {0, 2, 0, 0, WS_SHIP_CDEMO_SK, WEB_SALES, WS_SHIP_CDEMO_SK, 0}, + {0, 1, 0, 0, WS_SHIP_HDEMO_SK, WEB_SALES, WS_SHIP_HDEMO_SK, 0}, + {0, 1, 0, 0, WS_SHIP_ADDR_SK, WEB_SALES, WS_SHIP_ADDR_SK, 0}, + {0, 16, 0, 0, WS_WEB_PAGE_SK, WEB_SALES, WS_WEB_PAGE_SK, 0}, + {0, 16, 0, 0, WS_WEB_SITE_SK, WEB_SALES, WS_WEB_SITE_SK, 0}, + {0, 16, 0, 0, WS_SHIP_MODE_SK, WEB_SALES, WS_SHIP_MODE_SK, 0}, + {0, 16, 0, 0, WS_WAREHOUSE_SK, WEB_SALES, WS_WAREHOUSE_SK, 0}, + {0, 16, 0, 0, WS_PROMO_SK, WEB_SALES, WS_PROMO_SK, 0}, + {0, 1, 0, 0, WS_ORDER_NUMBER, WEB_SALES, WS_ORDER_NUMBER, 0}, + {0, 1, 0, 0, WS_PRICING_QUANTITY, WEB_SALES, WS_PRICING_QUANTITY, 0}, + {0, + 1, + 0, + 0, + WS_PRICING_WHOLESALE_COST, + WEB_SALES, + WS_PRICING_WHOLESALE_COST, + 0}, + {0, 0, 0, 0, WS_PRICING_LIST_PRICE, WEB_SALES, WS_PRICING_LIST_PRICE, 0}, + {0, + 0, + 0, + 0, + WS_PRICING_SALES_PRICE, + WEB_SALES, + WS_PRICING_SALES_PRICE, + 0}, + {0, + 0, + 0, + 0, + WS_PRICING_EXT_DISCOUNT_AMT, + WEB_SALES, + WS_PRICING_EXT_DISCOUNT_AMT, + 0}, + {0, + 0, + 0, + 0, + WS_PRICING_EXT_SALES_PRICE, + WEB_SALES, + WS_PRICING_EXT_SALES_PRICE, + 0}, + {0, + 0, + 0, + 0, + WS_PRICING_EXT_WHOLESALE_COST, + WEB_SALES, + WS_PRICING_EXT_WHOLESALE_COST, + 0}, + {0, + 0, + 0, + 0, + WS_PRICING_EXT_LIST_PRICE, + WEB_SALES, + WS_PRICING_EXT_LIST_PRICE, + 0}, + {0, 0, 0, 0, WS_PRICING_EXT_TAX, WEB_SALES, WS_PRICING_EXT_TAX, 0}, + {0, 0, 0, 0, WS_PRICING_COUPON_AMT, WEB_SALES, WS_PRICING_COUPON_AMT, 0}, + {0, + 0, + 0, + 0, + WS_PRICING_EXT_SHIP_COST, + WEB_SALES, + WS_PRICING_EXT_SHIP_COST, + 0}, + {0, 0, 0, 0, WS_PRICING_NET_PAID, WEB_SALES, WS_PRICING_NET_PAID, 0}, + {0, + 0, + 0, + 0, + WS_PRICING_NET_PAID_INC_TAX, + WEB_SALES, + WS_PRICING_NET_PAID_INC_TAX, + 0}, + {0, + 0, + 0, + 0, + WS_PRICING_NET_PAID_INC_SHIP, + WEB_SALES, + WS_PRICING_NET_PAID_INC_SHIP, + 0}, + {0, + 0, + 0, + 0, + WS_PRICING_NET_PAID_INC_SHIP_TAX, + WEB_SALES, + WS_PRICING_NET_PAID_INC_SHIP_TAX, + 0}, + {0, 0, 0, 0, WS_PRICING_NET_PROFIT, WEB_SALES, WS_PRICING_NET_PROFIT, 0}, + {0, 128, 0, 0, WS_PRICING, WEB_SALES, WS_PRICING, 0}, + {0, 32, 0, 0, WS_NULLS, WEB_SALES, WS_NULLS, 0}, + {0, 16, 0, 0, WR_IS_RETURNED, WEB_SALES, WR_IS_RETURNED, 0}, + {0, 0, 0, 0, WS_PERMUTATION, WEB_SALES, WS_PERMUTATION, 0}, + {0, 1, 0, 0, WEB_SITE_SK, WEB_SITE, WEB_SITE_SK, 0}, + {0, 1, 0, 0, WEB_SITE_ID, WEB_SITE, WEB_SITE_ID, 0}, + {0, 1, 0, 0, WEB_REC_START_DATE_ID, WEB_SITE, WEB_REC_START_DATE_ID, 0}, + {0, 1, 0, 0, WEB_REC_END_DATE_ID, WEB_SITE, WEB_REC_END_DATE_ID, 0}, + {0, 1, 0, 0, WEB_NAME, WEB_SITE, WEB_NAME, 0}, + {0, 1, 0, 0, WEB_OPEN_DATE, WEB_SITE, WEB_OPEN_DATE, 0}, + {0, 1, 0, 0, WEB_CLOSE_DATE, WEB_SITE, WEB_CLOSE_DATE, 0}, + {0, 1, 0, 0, WEB_CLASS, WEB_SITE, WEB_CLASS, 0}, + {0, 2, 0, 0, WEB_MANAGER, WEB_SITE, WEB_MANAGER, 0}, + {0, 1, 0, 0, WEB_MARKET_ID, WEB_SITE, WEB_MARKET_ID, 0}, + {0, 20, 0, 0, WEB_MARKET_CLASS, WEB_SITE, WEB_MARKET_CLASS, 0}, + {0, 100, 0, 0, WEB_MARKET_DESC, WEB_SITE, WEB_MARKET_DESC, 0}, + {0, 2, 0, 0, WEB_MARKET_MANAGER, WEB_SITE, WEB_MARKET_MANAGER, 0}, + {0, 1, 0, 0, WEB_COMPANY_ID, WEB_SITE, WEB_COMPANY_ID, 0}, + {0, 1, 0, 0, WEB_COMPANY_NAME, WEB_SITE, WEB_COMPANY_NAME, 0}, + {0, 1, 0, 0, WEB_ADDRESS_STREET_NUM, WEB_SITE, WEB_ADDRESS_STREET_NUM, 0}, + {0, + 1, + 0, + 0, + WEB_ADDRESS_STREET_NAME1, + WEB_SITE, + WEB_ADDRESS_STREET_NAME1, + 0}, + {0, + 1, + 0, + 0, + WEB_ADDRESS_STREET_TYPE, + WEB_SITE, + WEB_ADDRESS_STREET_TYPE, + 0}, + {0, 1, 0, 0, WEB_ADDRESS_SUITE_NUM, WEB_SITE, WEB_ADDRESS_SUITE_NUM, 0}, + {0, 1, 0, 0, WEB_ADDRESS_CITY, WEB_SITE, WEB_ADDRESS_CITY, 0}, + {0, 1, 0, 0, WEB_ADDRESS_COUNTY, WEB_SITE, WEB_ADDRESS_COUNTY, 0}, + {0, 1, 0, 0, WEB_ADDRESS_STATE, WEB_SITE, WEB_ADDRESS_STATE, 0}, + {0, 1, 0, 0, WEB_ADDRESS_ZIP, WEB_SITE, WEB_ADDRESS_ZIP, 0}, + {0, 1, 0, 0, WEB_ADDRESS_COUNTRY, WEB_SITE, WEB_ADDRESS_COUNTRY, 0}, + {0, 1, 0, 0, WEB_ADDRESS_GMT_OFFSET, WEB_SITE, WEB_ADDRESS_GMT_OFFSET, 0}, + {0, 1, 0, 0, WEB_TAX_PERCENTAGE, WEB_SITE, WEB_TAX_PERCENTAGE, 0}, + {0, 2, 0, 0, WEB_NULLS, WEB_SITE, WEB_NULLS, 0}, + {0, 7, 0, 0, WEB_ADDRESS, WEB_SITE, WEB_ADDRESS, 0}, + {0, 70, 0, 0, WEB_SCD, WEB_SITE, WEB_SCD, 0}, + {0, 0, 0, 0, DV_VERSION, DBGEN_VERSION, DV_VERSION, 0}, + {0, 0, 0, 0, DV_CREATE_DATE, DBGEN_VERSION, DV_CREATE_DATE, 0}, + {0, 0, 0, 0, DV_CREATE_TIME, DBGEN_VERSION, DV_CREATE_TIME, 0}, + {0, 0, 0, 0, DV_CMDLINE_ARGS, DBGEN_VERSION, DV_CMDLINE_ARGS, 0}, + {0, 0, 0, 0, VALIDATE_STREAM, DBGEN_VERSION, VALIDATE_STREAM, 0}, + {0, 0, 0, 0, S_BRAND_ID, S_BRAND, S_BRAND_ID, 0}, + {0, 0, 0, 0, S_BRAND_SUBCLASS_ID, S_BRAND, S_BRAND_SUBCLASS_ID, 0}, + {0, 1, 0, 0, S_BRAND_MANAGER_ID, S_BRAND, S_BRAND_MANAGER_ID, 0}, + {0, + 1, + 0, + 0, + S_BRAND_MANUFACTURER_ID, + S_BRAND, + S_BRAND_MANUFACTURER_ID, + 0}, + {0, 6, 0, 0, S_BRAND_NAME, S_BRAND, S_BRAND_NAME, 0}, + {0, 0, 0, 0, S_CADR_ID, S_CUSTOMER_ADDRESS, S_CADR_ID, 0}, + {0, + 1, + 0, + 0, + S_CADR_ADDRESS_STREET_NUMBER, + S_CUSTOMER_ADDRESS, + S_CADR_ADDRESS_STREET_NUMBER, + 0}, + {0, + 1, + 0, + 0, + S_CADR_ADDRESS_STREET_NAME1, + S_CUSTOMER_ADDRESS, + S_CADR_ADDRESS_STREET_NAME1, + 0}, + {0, + 1, + 0, + 0, + S_CADR_ADDRESS_STREET_NAME2, + S_CUSTOMER_ADDRESS, + S_CADR_ADDRESS_STREET_NAME2, + 0}, + {0, + 1, + 0, + 0, + S_CADR_ADDRESS_STREET_TYPE, + S_CUSTOMER_ADDRESS, + S_CADR_ADDRESS_STREET_TYPE, + 0}, + {0, + 1, + 0, + 0, + S_CADR_ADDRESS_SUITE_NUM, + S_CUSTOMER_ADDRESS, + S_CADR_ADDRESS_SUITE_NUM, + 0}, + {0, + 1, + 0, + 0, + S_CADR_ADDRESS_CITY, + S_CUSTOMER_ADDRESS, + S_CADR_ADDRESS_CITY, + 0}, + {0, + 1, + 0, + 0, + S_CADR_ADDRESS_COUNTY, + S_CUSTOMER_ADDRESS, + S_CADR_ADDRESS_COUNTY, + 0}, + {0, + 1, + 0, + 0, + S_CADR_ADDRESS_STATE, + S_CUSTOMER_ADDRESS, + S_CADR_ADDRESS_STATE, + 0}, + {0, + 1, + 0, + 0, + S_CADR_ADDRESS_ZIP, + S_CUSTOMER_ADDRESS, + S_CADR_ADDRESS_ZIP, + 0}, + {0, + 1, + 0, + 0, + S_CADR_ADDRESS_COUNTRY, + S_CUSTOMER_ADDRESS, + S_CADR_ADDRESS_COUNTRY, + 0}, + {0, 7, 0, 0, S_BADDR_ADDRESS, S_CUSTOMER_ADDRESS, CA_ADDRESS, 0}, + {0, 1, 0, 0, S_CALL_CENTER_ID, S_CALL_CENTER, S_CALL_CENTER_ID, 0}, + {0, + 1, + 0, + 0, + S_CALL_CENTER_DIVISION_ID, + S_CALL_CENTER, + S_CALL_CENTER_DIVISION_ID, + 0}, + {0, + 1, + 0, + 0, + S_CALL_CENTER_OPEN_DATE, + S_CALL_CENTER, + S_CALL_CENTER_OPEN_DATE, + 0}, + {0, + 0, + 0, + 0, + S_CALL_CENTER_CLOSED_DATE, + S_CALL_CENTER, + S_CALL_CENTER_CLOSED_DATE, + 0}, + {0, 0, 0, 0, S_CALL_CENTER_NAME, S_CALL_CENTER, S_CALL_CENTER_NAME, 0}, + {0, 0, 0, 0, S_CALL_CENTER_CLASS, S_CALL_CENTER, S_CALL_CENTER_CLASS, 0}, + {0, + 1, + 0, + 0, + S_CALL_CENTER_EMPLOYEES, + S_CALL_CENTER, + S_CALL_CENTER_EMPLOYEES, + 0}, + {0, 1, 0, 0, S_CALL_CENTER_SQFT, S_CALL_CENTER, S_CALL_CENTER_SQFT, 0}, + {0, 1, 0, 0, S_CALL_CENTER_HOURS, S_CALL_CENTER, S_CALL_CENTER_HOURS, 0}, + {0, + 1, + 0, + 0, + S_CALL_CENTER_MANAGER_ID, + S_CALL_CENTER, + S_CALL_CENTER_MANAGER_ID, + 0}, + {0, + 1, + 0, + 0, + S_CALL_CENTER_MARKET_ID, + S_CALL_CENTER, + S_CALL_CENTER_MARKET_ID, + 0}, + {0, + 1, + 0, + 0, + S_CALL_CENTER_ADDRESS_ID, + S_CALL_CENTER, + S_CALL_CENTER_ADDRESS_ID, + 0}, + {0, + 1, + 0, + 0, + S_CALL_CENTER_TAX_PERCENTAGE, + S_CALL_CENTER, + S_CALL_CENTER_TAX_PERCENTAGE, + 0}, + {0, 1, 0, 0, S_CALL_CENTER_SCD, S_CALL_CENTER, S_CALL_CENTER_SCD, 0}, + {0, 0, 0, 0, S_CATALOG_NUMBER, S_CATALOG, S_CATALOG_NUMBER, 0}, + {0, 1, 0, 0, S_CATALOG_START_DATE, S_CATALOG, S_CATALOG_START_DATE, 0}, + {0, 1, 0, 0, S_CATALOG_END_DATE, S_CATALOG, S_CATALOG_END_DATE, 0}, + {0, 10, 0, 0, S_CATALOG_DESC, S_CATALOG, S_CATALOG_DESC, 0}, + {0, 1, 0, 0, S_CATALOG_TYPE, S_CATALOG, S_CATALOG_TYPE, 0}, + {0, 0, 0, 0, S_CORD_ID, S_CATALOG_ORDER, S_CORD_ID, 0}, + {0, + 1, + 0, + 0, + S_CORD_BILL_CUSTOMER_ID, + S_CATALOG_ORDER, + S_CORD_BILL_CUSTOMER_ID, + 0}, + {0, + 2, + 0, + 0, + S_CORD_SHIP_CUSTOMER_ID, + S_CATALOG_ORDER, + S_CORD_SHIP_CUSTOMER_ID, + 0}, + {0, 1, 0, 0, S_CORD_ORDER_DATE, S_CATALOG_ORDER, S_CORD_ORDER_DATE, 0}, + {0, 1, 0, 0, S_CORD_ORDER_TIME, S_CATALOG_ORDER, S_CORD_ORDER_TIME, 0}, + {0, + 1, + 0, + 0, + S_CORD_SHIP_MODE_ID, + S_CATALOG_ORDER, + S_CORD_SHIP_MODE_ID, + 0}, + {0, + 1, + 0, + 0, + S_CORD_CALL_CENTER_ID, + S_CATALOG_ORDER, + S_CORD_CALL_CENTER_ID, + 0}, + {0, 1, 0, 0, S_CLIN_ITEM_ID, S_CATALOG_ORDER, S_CLIN_ITEM_ID, 0}, + {0, 100, 0, 0, S_CORD_COMMENT, S_CATALOG_ORDER, S_CORD_COMMENT, 0}, + {0, + 1, + 0, + 0, + S_CLIN_ORDER_ID, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_ORDER_ID, + 0}, + {0, + 0, + 0, + 0, + S_CLIN_LINE_NUMBER, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_LINE_NUMBER, + 0}, + {0, + 1, + 0, + 0, + S_CLIN_PROMOTION_ID, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_PROMOTION_ID, + 0}, + {0, + 1, + 0, + 0, + S_CLIN_QUANTITY, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_QUANTITY, + 0}, + {0, + 1, + 0, + 0, + S_CLIN_COUPON_AMT, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_COUPON_AMT, + 0}, + {0, + 1, + 0, + 0, + S_CLIN_WAREHOUSE_ID, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_WAREHOUSE_ID, + 0}, + {0, + 1, + 0, + 0, + S_CLIN_SHIP_DATE, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_SHIP_DATE, + 0}, + {0, + 1, + 0, + 0, + S_CLIN_CATALOG_ID, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_CATALOG_ID, + 0}, + {0, + 2, + 0, + 0, + S_CLIN_CATALOG_PAGE_ID, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_CATALOG_PAGE_ID, + 0}, + {0, 8, 0, 0, S_CLIN_PRICING, S_CATALOG_ORDER_LINEITEM, S_CLIN_PRICING, 0}, + {0, + 0, + 0, + 0, + S_CLIN_SHIP_COST, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_SHIP_COST, + 0}, + {0, + 1, + 0, + 0, + S_CLIN_IS_RETURNED, + S_CATALOG_ORDER_LINEITEM, + S_CLIN_IS_RETURNED, + 0}, + {0, 0, 0, 0, S_CLIN_PERMUTE, S_CATALOG_ORDER_LINEITEM, S_CLIN_PERMUTE, 0}, + {0, + 0, + 0, + 0, + S_CATALOG_PAGE_CATALOG_NUMBER, + S_CATALOG_PAGE, + S_CATALOG_PAGE_CATALOG_NUMBER, + 0}, + {0, + 0, + 0, + 0, + S_CATALOG_PAGE_NUMBER, + S_CATALOG_PAGE, + S_CATALOG_PAGE_NUMBER, + 0}, + {0, + 1, + 0, + 0, + S_CATALOG_PAGE_DEPARTMENT, + S_CATALOG_PAGE, + S_CATALOG_PAGE_DEPARTMENT, + 0}, + {0, 1, 0, 0, S_CP_ID, S_CATALOG_PAGE, S_CP_ID, 0}, + {0, 1, 0, 0, S_CP_START_DATE, S_CATALOG_PAGE, S_CP_START_DATE, 0}, + {0, 1, 0, 0, S_CP_END_DATE, S_CATALOG_PAGE, S_CP_END_DATE, 0}, + {0, 100, 0, 0, S_CP_DESCRIPTION, S_CATALOG_PAGE, CP_DESCRIPTION, 0}, + {0, 1, 0, 0, S_CP_TYPE, S_CATALOG_PAGE, S_CP_TYPE, 0}, + {0, + 1, + 0, + 0, + S_CATALOG_PROMOTIONAL_ITEM_CATALOG_NUMBER, + S_CATALOG_PROMOTIONAL_ITEM, + S_CATALOG_PROMOTIONAL_ITEM_CATALOG_NUMBER, + 0}, + {0, + 1, + 0, + 0, + S_CATALOG_PROMOTIONAL_ITEM_CATALOG_PAGE_NUMBER, + S_CATALOG_PROMOTIONAL_ITEM, + S_CATALOG_PROMOTIONAL_ITEM_CATALOG_PAGE_NUMBER, + 0}, + {0, + 1, + 0, + 0, + S_CATALOG_PROMOTIONAL_ITEM_ITEM_ID, + S_CATALOG_PROMOTIONAL_ITEM, + S_CATALOG_PROMOTIONAL_ITEM_ITEM_ID, + 0}, + {0, + 0, + 0, + 0, + S_CATALOG_PROMOTIONAL_ITEM_PROMOTION_ID, + S_CATALOG_PROMOTIONAL_ITEM, + S_CATALOG_PROMOTIONAL_ITEM_PROMOTION_ID, + 0}, + {0, + 9, + 0, + 0, + S_CRET_CALL_CENTER_ID, + S_CATALOG_RETURNS, + S_CRET_CALL_CENTER_ID, + 0}, + {0, 0, 0, 0, S_CRET_ORDER_ID, S_CATALOG_RETURNS, S_CRET_ORDER_ID, 0}, + {0, + 0, + 0, + 0, + S_CRET_LINE_NUMBER, + S_CATALOG_RETURNS, + S_CRET_LINE_NUMBER, + 0}, + {0, 0, 0, 0, S_CRET_ITEM_ID, S_CATALOG_RETURNS, S_CRET_ITEM_ID, 0}, + {0, + 0, + 0, + 0, + S_CRET_RETURN_CUSTOMER_ID, + S_CATALOG_RETURNS, + S_CRET_RETURN_CUSTOMER_ID, + 0}, + {0, + 0, + 0, + 0, + S_CRET_REFUND_CUSTOMER_ID, + S_CATALOG_RETURNS, + S_CRET_REFUND_CUSTOMER_ID, + 0}, + {0, 9, 0, 0, S_CRET_DATE, S_CATALOG_RETURNS, S_CRET_DATE, 0}, + {0, 18, 0, 0, S_CRET_TIME, S_CATALOG_RETURNS, S_CRET_TIME, 0}, + {0, 0, 0, 0, S_CRET_QUANTITY, S_CATALOG_RETURNS, S_CRET_QUANTITY, 0}, + {0, 0, 0, 0, S_CRET_AMOUNT, S_CATALOG_RETURNS, S_CRET_AMOUNT, 0}, + {0, 0, 0, 0, S_CRET_TAX, S_CATALOG_RETURNS, S_CRET_TAX, 0}, + {0, 0, 0, 0, S_CRET_FEE, S_CATALOG_RETURNS, S_CRET_FEE, 0}, + {0, 0, 0, 0, S_CRET_SHIP_COST, S_CATALOG_RETURNS, S_CRET_SHIP_COST, 0}, + {0, + 0, + 0, + 0, + S_CRET_REFUNDED_CASH, + S_CATALOG_RETURNS, + S_CRET_REFUNDED_CASH, + 0}, + {0, + 0, + 0, + 0, + S_CRET_REVERSED_CHARGE, + S_CATALOG_RETURNS, + S_CRET_REVERSED_CHARGE, + 0}, + {0, + 0, + 0, + 0, + S_CRET_MERCHANT_CREDIT, + S_CATALOG_RETURNS, + S_CRET_MERCHANT_CREDIT, + 0}, + {0, 9, 0, 0, S_CRET_REASON_ID, S_CATALOG_RETURNS, S_CRET_REASON_ID, 0}, + {0, 72, 0, 0, S_CRET_PRICING, S_CATALOG_RETURNS, S_CRET_PRICING, 0}, + {0, + 9, + 0, + 0, + S_CRET_SHIPMODE_ID, + S_CATALOG_RETURNS, + S_CRET_SHIPMODE_ID, + 0}, + {0, + 9, + 0, + 0, + S_CRET_WAREHOUSE_ID, + S_CATALOG_RETURNS, + S_CRET_WAREHOUSE_ID, + 0}, + {0, + 0, + 0, + 0, + S_CRET_CATALOG_PAGE_ID, + S_CATALOG_RETURNS, + S_CRET_CATALOG_PAGE_ID, + 0}, + {0, 0, 0, 0, S_CATEGORY_ID, S_CATEGORY, S_CATEGORY_ID, 0}, + {0, 0, 0, 0, S_CATEGORY_NAME, S_CATEGORY, S_CATEGORY_NAME, 0}, + {0, 10, 0, 0, S_CATEGORY_DESC, S_CATEGORY, S_CATEGORY_DESC, 0}, + {0, 0, 0, 0, S_CLASS_ID, S_CLASS, S_CLASS_ID, 0}, + {0, 1, 0, 0, S_CLASS_SUBCAT_ID, S_CLASS, S_CLASS_SUBCAT_ID, 0}, + {0, 10, 0, 0, S_CLASS_DESC, S_CLASS, S_CLASS_DESC, 0}, + {0, 0, 0, 0, S_COMPANY_ID, S_COMPANY, S_COMPANY_ID, 0}, + {0, 0, 0, 0, S_COMPANY_NAME, S_COMPANY, S_COMPANY_NAME, 0}, + {0, 0, 0, 0, S_CUST_ID, S_CUSTOMER, S_CUST_ID, 0}, + {0, 1, 0, 0, S_CUST_SALUTATION, S_CUSTOMER, S_CUST_SALUTATION, 0}, + {0, 1, 0, 0, S_CUST_LAST_NAME, S_CUSTOMER, S_CUST_LAST_NAME, 0}, + {0, 1, 0, 0, S_CUST_FIRST_NAME, S_CUSTOMER, S_CUST_FIRST_NAME, 0}, + {0, 1, 0, 0, S_CUST_PREFERRED_FLAG, S_CUSTOMER, S_CUST_PREFERRED_FLAG, 0}, + {0, 1, 0, 0, S_CUST_BIRTH_DATE, S_CUSTOMER, S_CUST_BIRTH_DATE, 0}, + {0, + 1, + 0, + 0, + S_CUST_FIRST_PURCHASE_DATE, + S_CUSTOMER, + S_CUST_FIRST_PURCHASE_DATE, + 0}, + {0, + 1, + 0, + 0, + S_CUST_FIRST_SHIPTO_DATE, + S_CUSTOMER, + S_CUST_FIRST_SHIPTO_DATE, + 0}, + {0, 1, 0, 0, S_CUST_BIRTH_COUNTRY, S_CUSTOMER, S_CUST_BIRTH_COUNTRY, 0}, + {0, 25, 0, 0, S_CUST_LOGIN, S_CUSTOMER, S_CUST_LOGIN, 0}, + {0, 23, 0, 0, S_CUST_EMAIL, S_CUSTOMER, S_CUST_EMAIL, 0}, + {0, 1, 0, 0, S_CUST_LAST_LOGIN, S_CUSTOMER, S_CUST_LAST_LOGIN, 0}, + {0, 1, 0, 0, S_CUST_LAST_REVIEW, S_CUSTOMER, S_CUST_LAST_REVIEW, 0}, + {0, + 4, + 0, + 0, + S_CUST_PRIMARY_MACHINE, + S_CUSTOMER, + S_CUST_PRIMARY_MACHINE, + 0}, + {0, + 4, + 0, + 0, + S_CUST_SECONDARY_MACHINE, + S_CUSTOMER, + S_CUST_SECONDARY_MACHINE, + 0}, + {0, 7, 0, 0, S_CUST_ADDRESS, S_CUSTOMER, S_CUST_ADDRESS, 0}, + {0, + 1, + 0, + 0, + S_CUST_ADDRESS_STREET_NUM, + S_CUSTOMER, + S_CUST_ADDRESS_STREET_NUM, + 0}, + {0, + 1, + 0, + 0, + S_CUST_ADDRESS_STREET_NAME1, + S_CUSTOMER, + S_CUST_ADDRESS_STREET_NAME1, + 0}, + {0, + 1, + 0, + 0, + S_CUST_ADDRESS_STREET_NAME2, + S_CUSTOMER, + S_CUST_ADDRESS_STREET_NAME2, + 0}, + {0, + 1, + 0, + 0, + S_CUST_ADDRESS_STREET_TYPE, + S_CUSTOMER, + S_CUST_ADDRESS_STREET_TYPE, + 0}, + {0, + 1, + 0, + 0, + S_CUST_ADDRESS_SUITE_NUM, + S_CUSTOMER, + S_CUST_ADDRESS_SUITE_NUM, + 0}, + {0, 1, 0, 0, S_CUST_ADDRESS_CITY, S_CUSTOMER, S_CUST_ADDRESS_CITY, 0}, + {0, 1, 0, 0, S_CUST_ADDRESS_ZIP, S_CUSTOMER, S_CUST_ADDRESS_ZIP, 0}, + {0, 1, 0, 0, S_CUST_ADDRESS_COUNTY, S_CUSTOMER, S_CUST_ADDRESS_COUNTY, 0}, + {0, 1, 0, 0, S_CUST_ADDRESS_STATE, S_CUSTOMER, S_CUST_ADDRESS_STATE, 0}, + {0, + 1, + 0, + 0, + S_CUST_ADDRESS_COUNTRY, + S_CUSTOMER, + S_CUST_ADDRESS_COUNTRY, + 0}, + {0, 1, 0, 0, S_CUST_LOCATION_TYPE, S_CUSTOMER, S_CUST_LOCATION_TYPE, 0}, + {0, 1, 0, 0, S_CUST_GENDER, S_CUSTOMER, S_CUST_GENDER, 0}, + {0, 1, 0, 0, S_CUST_MARITAL_STATUS, S_CUSTOMER, S_CUST_MARITAL_STATUS, 0}, + {0, 1, 0, 0, S_CUST_EDUCATION, S_CUSTOMER, S_CUST_EDUCATION, 0}, + {0, 1, 0, 0, S_CUST_CREDIT_RATING, S_CUSTOMER, S_CUST_CREDIT_RATING, 0}, + {0, + 1, + 0, + 0, + S_CUST_PURCHASE_ESTIMATE, + S_CUSTOMER, + S_CUST_PURCHASE_ESTIMATE, + 0}, + {0, 1, 0, 0, S_CUST_BUY_POTENTIAL, S_CUSTOMER, S_CUST_BUY_POTENTIAL, 0}, + {0, 1, 0, 0, S_CUST_DEPENDENT_CNT, S_CUSTOMER, S_CUST_DEPENDENT_CNT, 0}, + {0, 1, 0, 0, S_CUST_EMPLOYED_CNT, S_CUSTOMER, S_CUST_EMPLOYED_CNT, 0}, + {0, 1, 0, 0, S_CUST_COLLEGE_CNT, S_CUSTOMER, S_CUST_COLLEGE_CNT, 0}, + {0, 1, 0, 0, S_CUST_VEHICLE_CNT, S_CUSTOMER, S_CUST_VEHICLE_CNT, 0}, + {0, 1, 0, 0, S_CUST_INCOME, S_CUSTOMER, S_CUST_INCOME, 0}, + {0, 0, 0, 0, S_DIVISION_ID, S_DIVISION, S_DIVISION_ID, 0}, + {0, 0, 0, 0, S_DIVISION_COMPANY, S_DIVISION, S_DIVISION_COMPANY, 0}, + {0, 0, 0, 0, S_DIVISION_NAME, S_DIVISION, S_DIVISION_NAME, 0}, + {0, 1, 0, 0, S_INVN_WAREHOUSE, S_INVENTORY, S_INVN_WAREHOUSE, 0}, + {0, 1, 0, 0, S_INVN_ITEM, S_INVENTORY, S_INVN_ITEM, 0}, + {0, 2, 0, 0, S_INVN_DATE, S_INVENTORY, S_INVN_DATE, 0}, + {0, 1, 0, 0, S_INVN_QUANTITY, S_INVENTORY, S_INVN_QUANTITY, 0}, + {0, 1, 0, 0, S_ITEM_ID, S_ITEM, S_ITEM_ID, 0}, + {0, 0, 0, 0, S_ITEM_PERMUTE, S_ITEM, S_ITEM_PERMUTE, 0}, + {0, 1, 0, 0, S_ITEM_PRODUCT_ID, S_ITEM, S_ITEM_PRODUCT_ID, 0}, + {0, 200, 0, 0, S_ITEM_DESC, S_ITEM, I_ITEM_DESC, 0}, + {0, 2, 0, 0, S_ITEM_LIST_PRICE, S_ITEM, I_CURRENT_PRICE, 0}, + {0, 1, 0, 0, S_ITEM_WHOLESALE_COST, S_ITEM, I_WHOLESALE_COST, 0}, + {0, 1, 0, 0, S_ITEM_MANAGER_ID, S_ITEM, I_MANAGER_ID, 0}, + {0, 1, 0, 0, S_ITEM_SIZE, S_ITEM, I_SIZE, 0}, + {0, 50, 0, 0, S_ITEM_FORMULATION, S_ITEM, I_FORMULATION, 0}, + {0, 1, 0, 0, S_ITEM_FLAVOR, S_ITEM, I_COLOR, 0}, + {0, 1, 0, 0, S_ITEM_UNITS, S_ITEM, I_UNITS, 0}, + {0, 1, 0, 0, S_ITEM_CONTAINER, S_ITEM, I_CONTAINER, 0}, + {0, 1, 0, 0, S_ITEM_SCD, S_ITEM, I_SCD, 0}, + {0, 0, 0, 0, S_MANAGER_ID, S_MANAGER, S_MANAGER_ID, 0}, + {0, 2, 0, 0, S_MANAGER_NAME, S_MANAGER, S_MANAGER_NAME, 0}, + {0, 0, 0, 0, S_MANUFACTURER_ID, S_MANUFACTURER, S_MANUFACTURER_ID, 0}, + {0, 0, 0, 0, S_MANUFACTURER_NAME, S_MANUFACTURER, S_MANUFACTURER_NAME, 0}, + {0, 0, 0, 0, S_MARKET_ID, S_MARKET, S_MARKET_ID, 0}, + {0, 0, 0, 0, S_MARKET_CLASS_NAME, S_MARKET, S_MARKET_CLASS_NAME, 0}, + {0, 10, 0, 0, S_MARKET_DESC, S_MARKET, S_MARKET_DESC, 0}, + {0, 1, 0, 0, S_MARKET_MANAGER_ID, S_MARKET, S_MARKET_MANAGER_ID, 0}, + {0, 0, 0, 0, S_PRODUCT_ID, S_PRODUCT, S_PRODUCT_ID, 0}, + {0, 1, 0, 0, S_PRODUCT_BRAND_ID, S_PRODUCT, S_PRODUCT_BRAND_ID, 0}, + {0, 0, 0, 0, S_PRODUCT_NAME, S_PRODUCT, S_PRODUCT_NAME, 0}, + {0, 1, 0, 0, S_PRODUCT_TYPE, S_PRODUCT, S_PRODUCT_TYPE, 0}, + {0, 1, 0, 0, S_PROMOTION_ID, S_PROMOTION, S_PROMOTION_ID, 0}, + {0, 1, 0, 0, S_PROMOTION_ITEM_ID, S_PROMOTION, S_PROMOTION_ITEM_ID, 0}, + {0, + 1, + 0, + 0, + S_PROMOTION_START_DATE, + S_PROMOTION, + S_PROMOTION_START_DATE, + 0}, + {0, 1, 0, 0, S_PROMOTION_END_DATE, S_PROMOTION, S_PROMOTION_END_DATE, 0}, + {0, 1, 0, 0, S_PROMOTION_COST, S_PROMOTION, S_PROMOTION_COST, 0}, + {0, + 1, + 0, + 0, + S_PROMOTION_RESPONSE_TARGET, + S_PROMOTION, + S_PROMOTION_RESPONSE_TARGET, + 0}, + {0, 0, 0, 0, S_PROMOTION_DMAIL, S_PROMOTION, S_PROMOTION_DMAIL, 0}, + {0, 0, 0, 0, S_PROMOTION_EMAIL, S_PROMOTION, S_PROMOTION_EMAIL, 0}, + {0, 0, 0, 0, S_PROMOTION_CATALOG, S_PROMOTION, S_PROMOTION_CATALOG, 0}, + {0, 0, 0, 0, S_PROMOTION_TV, S_PROMOTION, S_PROMOTION_TV, 0}, + {0, 0, 0, 0, S_PROMOTION_RADIO, S_PROMOTION, S_PROMOTION_RADIO, 0}, + {0, 0, 0, 0, S_PROMOTION_PRESS, S_PROMOTION, S_PROMOTION_PRESS, 0}, + {0, 0, 0, 0, S_PROMOTION_EVENT, S_PROMOTION, S_PROMOTION_EVENT, 0}, + {0, 0, 0, 0, S_PROMOTION_DEMO, S_PROMOTION, S_PROMOTION_DEMO, 0}, + {0, 100, 0, 0, S_PROMOTION_DETAILS, S_PROMOTION, P_CHANNEL_DETAILS, 0}, + {0, 1, 0, 0, S_PROMOTION_PURPOSE, S_PROMOTION, S_PROMOTION_PURPOSE, 0}, + {0, + 1, + 0, + 0, + S_PROMOTION_DISCOUNT_ACTIVE, + S_PROMOTION, + S_PROMOTION_DISCOUNT_ACTIVE, + 0}, + {0, + 1, + 0, + 0, + S_PROMOTION_DISCOUNT_PCT, + S_PROMOTION, + S_PROMOTION_DISCOUNT_PCT, + 0}, + {0, 0, 0, 0, S_PROMOTION_NAME, S_PROMOTION, S_PROMOTION_NAME, 0}, + {0, 1, 0, 0, S_PROMOTION_BITFIELD, S_PROMOTION, S_PROMOTION_BITFIELD, 0}, + {0, 0, 0, 0, S_PURCHASE_ID, S_PURCHASE, S_PURCHASE_ID, 0}, + {0, 1, 0, 0, S_PURCHASE_STORE_ID, S_PURCHASE, S_PURCHASE_STORE_ID, 0}, + {0, + 1, + 0, + 0, + S_PURCHASE_CUSTOMER_ID, + S_PURCHASE, + S_PURCHASE_CUSTOMER_ID, + 0}, + {0, 1, 0, 0, S_PURCHASE_DATE, S_PURCHASE, S_PURCHASE_DATE, 0}, + {0, 1, 0, 0, S_PURCHASE_TIME, S_PURCHASE, S_PURCHASE_TIME, 0}, + {0, 1, 0, 0, S_PURCHASE_REGISTER, S_PURCHASE, S_PURCHASE_REGISTER, 0}, + {0, 1, 0, 0, S_PURCHASE_CLERK, S_PURCHASE, S_PURCHASE_CLERK, 0}, + {0, 100, 0, 0, S_PURCHASE_COMMENT, S_PURCHASE, S_PURCHASE_COMMENT, 0}, + {0, 7, 0, 0, S_PURCHASE_PRICING, S_PURCHASE, S_PURCHASE_PRICING, 0}, + {0, 1, 0, 0, S_PLINE_ITEM_ID, S_PURCHASE, S_PLINE_ITEM_ID, 0}, + {0, + 12, + 0, + 0, + S_PLINE_PURCHASE_ID, + S_PURCHASE_LINEITEM, + S_PLINE_PURCHASE_ID, + 0}, + {0, 12, 0, 0, S_PLINE_NUMBER, S_PURCHASE_LINEITEM, S_PLINE_NUMBER, 0}, + {0, + 12, + 0, + 0, + S_PLINE_PROMOTION_ID, + S_PURCHASE_LINEITEM, + S_PLINE_PROMOTION_ID, + 0}, + {0, + 12, + 0, + 0, + S_PLINE_SALE_PRICE, + S_PURCHASE_LINEITEM, + S_PLINE_SALE_PRICE, + 0}, + {0, 12, 0, 0, S_PLINE_QUANTITY, S_PURCHASE_LINEITEM, S_PLINE_QUANTITY, 0}, + {0, + 12, + 0, + 0, + S_PLINE_COUPON_AMT, + S_PURCHASE_LINEITEM, + S_PLINE_COUPON_AMT, + 0}, + {0, 1200, 0, 0, S_PLINE_COMMENT, S_PURCHASE_LINEITEM, S_PLINE_COMMENT, 0}, + {0, 96, 0, 0, S_PLINE_PRICING, S_PURCHASE_LINEITEM, S_PLINE_PRICING, 0}, + {0, + 12, + 0, + 0, + S_PLINE_IS_RETURNED, + S_PURCHASE_LINEITEM, + S_PLINE_IS_RETURNED, + 0}, + {0, 0, 0, 0, S_PLINE_PERMUTE, S_PURCHASE_LINEITEM, S_PLINE_PERMUTE, 0}, + {0, 0, 0, 0, S_REASON_ID, S_REASON, S_REASON_ID, 0}, + {0, 10, 0, 0, S_REASON_DESC, S_REASON, S_REASON_DESC, 0}, + {0, 1, 0, 0, S_STORE_ID, S_STORE, S_STORE_ID, 0}, + {0, 1, 0, 0, S_STORE_ADDRESS_ID, S_STORE, S_STORE_ADDRESS_ID, 0}, + {0, 1, 0, 0, S_STORE_DIVISION_ID, S_STORE, S_STORE_DIVISION_ID, 0}, + {0, 1, 0, 0, S_STORE_OPEN_DATE, S_STORE, S_STORE_OPEN_DATE, 0}, + {0, 1, 0, 0, S_STORE_CLOSE_DATE, S_STORE, S_STORE_CLOSE_DATE, 0}, + {0, 0, 0, 0, S_STORE_NAME, S_STORE, S_STORE_NAME, 0}, + {0, 0, 0, 0, S_STORE_CLASS, S_STORE, S_STORE_CLASS, 0}, + {0, 1, 0, 0, S_STORE_EMPLOYEES, S_STORE, S_STORE_EMPLOYEES, 0}, + {0, 1, 0, 0, S_STORE_FLOOR_SPACE, S_STORE, S_STORE_FLOOR_SPACE, 0}, + {0, 1, 0, 0, S_STORE_HOURS, S_STORE, S_STORE_HOURS, 0}, + {0, + 0, + 0, + 0, + S_STORE_MARKET_MANAGER_ID, + S_STORE, + S_STORE_MARKET_MANAGER_ID, + 0}, + {0, 1, 0, 0, S_STORE_MANAGER_ID, S_STORE, S_STORE_MANAGER_ID, 0}, + {0, 1, 0, 0, S_STORE_MARKET_ID, S_STORE, S_STORE_MARKET_ID, 0}, + {0, + 1, + 0, + 0, + S_STORE_GEOGRAPHY_CLASS, + S_STORE, + S_STORE_GEOGRAPHY_CLASS, + 0}, + {0, 1, 0, 0, S_STORE_TAX_PERCENTAGE, S_STORE, S_STORE_TAX_PERCENTAGE, 0}, + {0, + 1, + 0, + 0, + S_SITM_PROMOTION_ID, + S_STORE_PROMOTIONAL_ITEM, + S_SITM_PROMOTION_ID, + 0}, + {0, 1, 0, 0, S_SITM_ITEM_ID, S_STORE_PROMOTIONAL_ITEM, S_SITM_ITEM_ID, 0}, + {0, + 1, + 0, + 0, + S_SITM_STORE_ID, + S_STORE_PROMOTIONAL_ITEM, + S_SITM_STORE_ID, + 0}, + {0, 0, 0, 0, S_SRET_STORE_ID, S_STORE_RETURNS, S_SRET_STORE_ID, 0}, + {0, 0, 0, 0, S_SRET_PURCHASE_ID, S_STORE_RETURNS, S_SRET_PURCHASE_ID, 0}, + {0, 0, 0, 0, S_SRET_LINENUMBER, S_STORE_RETURNS, S_SRET_LINENUMBER, 0}, + {0, 0, 0, 0, S_SRET_ITEM_ID, S_STORE_RETURNS, S_SRET_ITEM_ID, 0}, + {0, 0, 0, 0, S_SRET_CUSTOMER_ID, S_STORE_RETURNS, S_SRET_CUSTOMER_ID, 0}, + {0, 24, 0, 0, S_SRET_RETURN_DATE, S_STORE_RETURNS, S_SRET_RETURN_DATE, 0}, + {0, 12, 0, 0, S_SRET_RETURN_TIME, S_STORE_RETURNS, S_SRET_RETURN_TIME, 0}, + {0, + 0, + 0, + 0, + S_SRET_TICKET_NUMBER, + S_STORE_RETURNS, + S_SRET_TICKET_NUMBER, + 0}, + {0, + 0, + 0, + 0, + S_SRET_RETURN_QUANTITY, + S_STORE_RETURNS, + S_SRET_RETURN_QUANTITY, + 0}, + {0, 0, 0, 0, S_SRET_RETURN_AMT, S_STORE_RETURNS, S_SRET_RETURN_AMT, 0}, + {0, 0, 0, 0, S_SRET_RETURN_TAX, S_STORE_RETURNS, S_SRET_RETURN_TAX, 0}, + {0, 0, 0, 0, S_SRET_RETURN_FEE, S_STORE_RETURNS, S_SRET_RETURN_FEE, 0}, + {0, + 0, + 0, + 0, + S_SRET_RETURN_SHIP_COST, + S_STORE_RETURNS, + S_SRET_RETURN_SHIP_COST, + 0}, + {0, + 0, + 0, + 0, + S_SRET_REFUNDED_CASH, + S_STORE_RETURNS, + S_SRET_REFUNDED_CASH, + 0}, + {0, + 0, + 0, + 0, + S_SRET_REVERSED_CHARGE, + S_STORE_RETURNS, + S_SRET_REVERSED_CHARGE, + 0}, + {0, + 0, + 0, + 0, + S_SRET_MERCHANT_CREDIT, + S_STORE_RETURNS, + S_SRET_MERCHANT_CREDIT, + 0}, + {0, 12, 0, 0, S_SRET_REASON_ID, S_STORE_RETURNS, S_SRET_REASON_ID, 0}, + {0, 84, 0, 0, S_SRET_PRICING, S_STORE_RETURNS, S_SRET_PRICING, 0}, + {0, 0, 0, 0, S_SBCT_ID, S_SUBCATEGORY, S_SBCT_ID, 0}, + {0, 1, 0, 0, S_SBCT_CATEGORY_ID, S_SUBCATEGORY, S_SBCT_CATEGORY_ID, 0}, + {0, 0, 0, 0, S_SBCT_NAME, S_SUBCATEGORY, S_SBCT_NAME, 0}, + {0, 10, 0, 0, S_SBCT_DESC, S_SUBCATEGORY, S_SBCT_DESC, 0}, + {0, 0, 0, 0, S_SUBC_ID, S_SUBCLASS, S_SUBC_ID, 0}, + {0, 1, 0, 0, S_SUBC_CLASS_ID, S_SUBCLASS, S_SUBC_CLASS_ID, 0}, + {0, 0, 0, 0, S_SUBC_NAME, S_SUBCLASS, S_SUBC_NAME, 0}, + {0, 10, 0, 0, S_SUBC_DESC, S_SUBCLASS, S_SUBC_DESC, 0}, + {0, 1, 0, 0, S_WRHS_ID, S_WAREHOUSE, S_WRHS_ID, 0}, + {0, 10, 0, 0, S_WRHS_DESC, S_WAREHOUSE, S_WRHS_DESC, 0}, + {0, 1, 0, 0, S_WRHS_SQFT, S_WAREHOUSE, S_WRHS_SQFT, 0}, + {0, 1, 0, 0, S_WRHS_ADDRESS_ID, S_WAREHOUSE, S_WRHS_ADDRESS_ID, 0}, + {0, 1, 0, 0, S_WORD_ID, S_WEB_ORDER, S_WORD_ID, 0}, + {0, + 1, + 0, + 0, + S_WORD_BILL_CUSTOMER_ID, + S_WEB_ORDER, + S_WORD_BILL_CUSTOMER_ID, + 0}, + {0, + 2, + 0, + 0, + S_WORD_SHIP_CUSTOMER_ID, + S_WEB_ORDER, + S_WORD_SHIP_CUSTOMER_ID, + 0}, + {0, 1, 0, 0, S_WORD_ORDER_DATE, S_WEB_ORDER, S_WORD_ORDER_DATE, 0}, + {0, 1, 0, 0, S_WORD_ORDER_TIME, S_WEB_ORDER, S_WORD_ORDER_TIME, 0}, + {0, 1, 0, 0, S_WORD_SHIP_MODE_ID, S_WEB_ORDER, S_WORD_SHIP_MODE_ID, 0}, + {0, 1, 0, 0, S_WORD_WEB_SITE_ID, S_WEB_ORDER, S_WORD_WEB_SITE_ID, 0}, + {0, 100, 0, 0, S_WORD_COMMENT, S_WEB_ORDER, S_WORD_COMMENT, 0}, + {0, 1, 0, 0, S_WLIN_ITEM_ID, S_WEB_ORDER, S_WLIN_ITEM_ID, 0}, + {0, 12, 0, 0, S_WLIN_ID, S_WEB_ORDER_LINEITEM, S_WLIN_ID, 0}, + {0, + 0, + 0, + 0, + S_WLIN_LINE_NUMBER, + S_WEB_ORDER_LINEITEM, + S_WLIN_LINE_NUMBER, + 0}, + {0, + 12, + 0, + 0, + S_WLIN_PROMOTION_ID, + S_WEB_ORDER_LINEITEM, + S_WLIN_PROMOTION_ID, + 0}, + {0, 12, 0, 0, S_WLIN_QUANTITY, S_WEB_ORDER_LINEITEM, S_WLIN_QUANTITY, 0}, + {0, + 12, + 0, + 0, + S_WLIN_COUPON_AMT, + S_WEB_ORDER_LINEITEM, + S_WLIN_COUPON_AMT, + 0}, + {0, + 12, + 0, + 0, + S_WLIN_WAREHOUSE_ID, + S_WEB_ORDER_LINEITEM, + S_WLIN_WAREHOUSE_ID, + 0}, + {0, + 12, + 0, + 0, + S_WLIN_SHIP_DATE, + S_WEB_ORDER_LINEITEM, + S_WLIN_SHIP_DATE, + 0}, + {0, + 12, + 0, + 0, + S_WLIN_WEB_PAGE_ID, + S_WEB_ORDER_LINEITEM, + S_WLIN_WEB_PAGE_ID, + 0}, + {0, 96, 0, 0, S_WLIN_PRICING, S_WEB_ORDER_LINEITEM, S_WLIN_PRICING, 0}, + {0, 0, 0, 0, S_WLIN_SHIP_COST, S_WEB_ORDER_LINEITEM, S_WLIN_SHIP_COST, 0}, + {0, + 12, + 0, + 0, + S_WLIN_IS_RETURNED, + S_WEB_ORDER_LINEITEM, + S_WLIN_IS_RETURNED, + 0}, + {0, 0, 0, 0, S_WLIN_PERMUTE, S_WEB_ORDER_LINEITEM, S_WLIN_PERMUTE, 0}, + {0, 1, 0, 0, S_WPAG_SITE_ID, S_WEB_PAGE, S_WPAG_SITE_ID, 0}, + {0, 1, 0, 0, S_WPAG_ID, S_WEB_PAGE, S_WPAG_ID, 0}, + {0, 1, 0, 0, S_WPAG_CREATE_DATE, S_WEB_PAGE, S_WPAG_CREATE_DATE, 0}, + {0, 1, 0, 0, S_WPAG_ACCESS_DATE, S_WEB_PAGE, S_WPAG_ACCESS_DATE, 0}, + {0, 1, 0, 0, S_WPAG_AUTOGEN_FLAG, S_WEB_PAGE, S_WPAG_AUTOGEN_FLAG, 0}, + {0, 1, 0, 0, S_WPAG_DEPARTMENT, S_WEB_PAGE, S_WPAG_DEPARTMENT, 0}, + {0, 1, 0, 0, S_WPAG_URL, S_WEB_PAGE, S_WPAG_URL, 0}, + {0, 1, 0, 0, S_WPAG_TYPE, S_WEB_PAGE, S_WPAG_TYPE, 0}, + {0, 1, 0, 0, S_WPAG_CHAR_CNT, S_WEB_PAGE, S_WPAG_CHAR_CNT, 0}, + {0, 1, 0, 0, S_WPAG_LINK_CNT, S_WEB_PAGE, S_WPAG_LINK_CNT, 0}, + {0, 1, 0, 0, S_WPAG_IMAGE_CNT, S_WEB_PAGE, S_WPAG_IMAGE_CNT, 0}, + {0, 1, 0, 0, S_WPAG_MAX_AD_CNT, S_WEB_PAGE, S_WPAG_MAX_AD_CNT, 0}, + {0, 0, 0, 0, S_WPAG_PERMUTE, S_WEB_PAGE, S_WPAG_PERMUTE, 0}, + {0, 1, 0, 0, S_WITM_SITE_ID, S_WEB_PROMOTIONAL_ITEM, S_WITM_SITE_ID, 0}, + {0, 1, 0, 0, S_WITM_PAGE_ID, S_WEB_PROMOTIONAL_ITEM, S_WITM_PAGE_ID, 0}, + {0, 1, 0, 0, S_WITM_ITEM_ID, S_WEB_PROMOTIONAL_ITEM, S_WITM_ITEM_ID, 0}, + {0, + 1, + 0, + 0, + S_WITM_PROMOTION_ID, + S_WEB_PROMOTIONAL_ITEM, + S_WITM_PROMOTION_ID, + 0}, + {0, 0, 0, 0, S_WRET_SITE_ID, S_WEB_RETURNS, S_WRET_SITE_ID, 0}, + {0, 0, 0, 0, S_WRET_ORDER_ID, S_WEB_RETURNS, S_WRET_ORDER_ID, 0}, + {0, 0, 0, 0, S_WRET_LINE_NUMBER, S_WEB_RETURNS, S_WRET_LINE_NUMBER, 0}, + {0, 0, 0, 0, S_WRET_ITEM_ID, S_WEB_RETURNS, S_WRET_ITEM_ID, 0}, + {0, + 0, + 0, + 0, + S_WRET_RETURN_CUST_ID, + S_WEB_RETURNS, + S_WRET_RETURN_CUST_ID, + 0}, + {0, + 0, + 0, + 0, + S_WRET_REFUND_CUST_ID, + S_WEB_RETURNS, + S_WRET_REFUND_CUST_ID, + 0}, + {0, 24, 0, 0, S_WRET_RETURN_DATE, S_WEB_RETURNS, S_WRET_RETURN_DATE, 0}, + {0, 12, 0, 0, S_WRET_RETURN_TIME, S_WEB_RETURNS, S_WRET_RETURN_TIME, 0}, + {0, 12, 0, 0, S_WRET_REASON_ID, S_WEB_RETURNS, S_WRET_REASON_ID, 0}, + {0, 84, 0, 0, S_WRET_PRICING, S_WEB_RETURNS, S_WRET_PRICING, 0}, + {0, 1, 0, 0, S_WSIT_ID, S_WEB_SITE, S_WSIT_ID, 0}, + {0, 1, 0, 0, S_WSIT_OPEN_DATE, S_WEB_SITE, S_WSIT_OPEN_DATE, 0}, + {0, 1, 0, 0, S_WSIT_CLOSE_DATE, S_WEB_SITE, S_WSIT_CLOSE_DATE, 0}, + {0, 0, 0, 0, S_WSIT_NAME, S_WEB_SITE, S_WSIT_NAME, 0}, + {0, 1, 0, 0, S_WSIT_ADDRESS_ID, S_WEB_SITE, S_WSIT_ADDRESS_ID, 0}, + {0, 1, 0, 0, S_WSIT_DIVISION_ID, S_WEB_SITE, S_WSIT_DIVISION_ID, 0}, + {0, 1, 0, 0, S_WSIT_CLASS, S_WEB_SITE, S_WSIT_CLASS, 0}, + {0, 1, 0, 0, S_WSIT_MANAGER_ID, S_WEB_SITE, S_WSIT_MANAGER_ID, 0}, + {0, 1, 0, 0, S_WSIT_MARKET_ID, S_WEB_SITE, S_WSIT_MARKET_ID, 0}, + {0, 1, 0, 0, S_WSIT_TAX_PERCENTAGE, S_WEB_SITE, S_WSIT_TAX_PERCENTAGE, 0}, + {0, 0, 0, 0, S_ZIPG_ZIP, S_ZIPG, S_ZIPG_ZIP, 0}, + {0, 0, 0, 0, S_ZIPG_GMT, S_ZIPG, S_ZIPG_GMT, 0}, + {-1, -1, -1, -1, -1, -1, -1, 0}}; + + void Reset(); +}; + +/* must match WriteDist() in dcomp.c */ +#define IDX_SIZE (D_NAME_LEN + 7 * sizeof(int)) + +int dist_op( + void* dest, + int op, + const char* d_name, + int vset, + int wset, + int stream, + DSDGenContext& dsdGenContext); +#define pick_distribution(dest, dist, v, w, s, dsdGenContext) \ + dist_op(dest, 0, dist, v, w, s, dsdGenContext) +#define dist_member(dest, dist, v, w, dsdGenContext) \ + dist_op(dest, 1, dist, v, w, 0, dsdGenContext) +#define dist_max(dist, w, dsdGenContext) dist->maximums[w - 1] +int dist_weight( + int* dest, + const char* d, + int index, + int wset, + DSDGenContext& dsdGenContext); +int distsize(const char* szDistname, DSDGenContext& dsdGenContext); +int dist_type(const char* szDistName, int vset, DSDGenContext& dsdGenContext); +const d_idx_t* find_dist(const char* name); +int IntegrateDist( + const char* szDistName, + int nPct, + int nStartIndex, + int nWeightSet, + DSDGenContext& dsdGenContext); +void dump_dist(const char* szName, DSDGenContext& dsdGenContext); +int dist_active( + const char* szName, + int nWeightSet, + DSDGenContext& dsdGenContext); +int DistNameIndex( + const char* szDist, + int nNameType, + const char* szName, + DSDGenContext& dsdGenContext); +int DistSizeToShiftWidth( + const char* szDist, + int nWeightSet, + DSDGenContext& dsdGenContext); +int MatchDistWeight( + void* dest, + const char* szDist, + int nWeight, + int nWeightSet, + int ValueSet, + DSDGenContext& dsdGenContext); +int findDistValue( + const char* szValue, + const char* szDistName, + int ValueSet, + DSDGenContext& dsdGenContext); +int di_compare(const void* op1, const void* op2); +int load_dists(); + +#define DIST_UNIFORM 0x0001 +#define DIST_EXPONENTIAL 0x0002 +/* sales and returns are special; they must match calendar.dst */ +#define DIST_SALES 3 +#define DIST_RETURNS 5 +#define DIST_CHAR 0x0004 +#define DIST_INT 0x0008 +#define DIST_NAMES_SET 0xff00 + +/* DistNameIndex needs to know what sort of name we are trying to match */ +#define VALUE_NAME 0x0000 +#define WEIGHT_NAME 0x0001 diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/error_msg.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/error_msg.h new file mode 100644 index 0000000000000..b8571ef643055 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/error_msg.h @@ -0,0 +1,76 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#define QERR_OK 0 +#define QERR_NO_FILE -1 +#define QERR_LINE_TOO_LONG -2 +#define QERR_NO_MEMORY -3 +#define QERR_SYNTAX -4 +#define QERR_RANGE_ERROR -5 +#define QERR_NON_UNIQUE -6 +#define QERR_BAD_NAME -7 +#define QERR_DEFINE_OVERFLOW -8 +#define QERR_INVALID_TAG -9 +#define QERR_READ_FAILED -10 +#define QERR_TEMPLATE_OVERFLOW -11 +#define QERR_ONE_WORKLOAD -12 +#define QERR_CLASS_REDEFINE -13 +#define QERR_DUP_QUERY -14 +#define QERR_OPEN_FAILED -15 +#define QERR_NOT_IMPLEMENTED -16 +#define QERR_STR_TRUNCATED -17 +#define QERR_BAD_STRING -18 +#define QERR_WRITE_FAILED -19 +#define QERR_NO_TYPE -20 +#define QERR_NO_WEIGHT -21 +#define QERR_NO_LIMIT -22 +#define QERR_BAD_PERCENT -23 +#define QERR_ROWCOUNT_NAME -24 +#define QERR_NO_EXPR -25 +#define QERR_NO_INIT -26 +#define QERR_NO_NORMAL_RANGE -27 +#define QERR_UNBALANCED -28 +#define QERR_INCLUDE_OVERFLOW -29 +#define QERR_BAD_PARAMS -30 +#define DBGEN_ERROR_HIERACHY_ORDER -31 +#define QERR_NAMES_EARLY -32 +#define QERR_ARG_OVERFLOW -33 +#define QERR_INVALID_ARG -34 +#define QERR_RANGE_LIST -35 +#define QERR_BAD_SCALE -36 +#define QERR_BAD_PARAM -37 +#define QERR_BAD_JOIN -38 +#define QERR_TABLE_NOP -39 +#define QERR_TABLE_CHILD -40 +#define QERR_CMDLINE_TOO_LONG -41 +#define QERR_NO_QUERYLIST -42 +#define QERR_QUERY_RANGE -43 +#define QERR_MODIFIED_PARAM -44 +#define QERR_RANGE_OVERRUN -45 +#define QERR_QUALIFICATION_SCALE -46 +#define QERR_TABLE_UPDATE -47 +#define MAX_ERROR 47 + +typedef struct ERR_MSG_T { + int flags; + const char* prompt; +} err_msg_t; + +/* Flag determine formating */ +#define EFLG_NO_ARG 0x0000 +#define EFLG_STR_ARG 0x0001 +#define EFLG_ARG_MASK 0x0001 + +#define EFLG_SYSTEM 0x0002 + +int ReportError(int nError, const char* arg, int bExit); +int ReportErrorNoLine(int nError, const char* arg, int bExit); +void SetErrorGlobals(char* szFileName, int* pnLineNumber); diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/genrand.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/genrand.h new file mode 100644 index 0000000000000..6cec1e25d9af3 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/genrand.h @@ -0,0 +1,84 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef GENRAND_H +#define GENRAND_H + +#include "address.h" +#include "date.h" +#include "decimal.h" +#include "dist.h" + +extern rng_t Streams[]; + +#define FL_SEED_OVERRUN 0x0001 + +#define ALPHANUM "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789" +#define DIGITS "0123456789" + +#define RNG_SEED 19620718 + +int genrand_integer( + int* dest, + int dist, + int min, + int max, + int mean, + int stream, + DSDGenContext& dsdGenContext); +int genrand_decimal( + decimal_t* dest, + int dist, + decimal_t* min, + decimal_t* max, + decimal_t* mean, + int stream, + DSDGenContext& dsdGenContext); +int genrand_date( + date_t* dest, + int dist, + date_t* min, + date_t* max, + date_t* mean, + int stream, + DSDGenContext& dsdGenContext); +ds_key_t genrand_key( + ds_key_t* dest, + int dist, + ds_key_t min, + ds_key_t max, + ds_key_t mean, + int stream, + DSDGenContext& dsdGenContext); +int gen_charset( + char* dest, + char* set, + int min, + int max, + int stream, + DSDGenContext& dsdGenContext); +int dump_seeds_ds(int tbl); +void init_rand(DSDGenContext& dsdGenContext); +void skip_random(int s, ds_key_t count, DSDGenContext& dsdGenContext); +int RNGReset(int nTable); +long next_random(int nStream, DSDGenContext& dsdGenContext); +void genrand_email( + char* pEmail, + char* pFirst, + char* pLast, + int nColumn, + DSDGenContext& dsdGenContext); +void genrand_ipaddr(char* pDest, int nColumn, DSDGenContext& dsdGenContext); +int genrand_url(char* pDest, int nColumn); +int setSeed(int nStream, int nValue, DSDGenContext& dsdGenContext); +void resetSeeds(int nTable, DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/grammar.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/grammar.h new file mode 100644 index 0000000000000..31a12acd570dd --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/grammar.h @@ -0,0 +1,30 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef GRAMMAR_H +#define GRAMMAR_H + +typedef struct TOKEN_T { + int index; + char word[40]; + int (*handler)(char* s, struct TOKEN_T* t); +} token_t; + +#define COMMENT_CHAR '-' +#define STMT_END ';' +int ParseFile(char* szPath); +int FindToken(char* name); +void SetTokens(token_t* t); +char* ProcessStr(char* stmt, token_t* pTokens); +char* SafeStrtok(char* string, char* delims); +extern token_t* pTokens; + +#endif /* GRAMMAR_H */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/grammar_support.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/grammar_support.h new file mode 100644 index 0000000000000..b629eaad4a0ce --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/grammar_support.h @@ -0,0 +1,35 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef GRAMMAR_SUPPORT_H +#define GRAMMAR_SUPPORT_H +/* + * entry in the file stack used to manage multiple input file and include files + */ +typedef struct FILE_REF_T { + FILE* file; + char* name; + int line_number; + void* pContext; + struct FILE_REF_T* pNext; +#if defined(MKS) || defined(FLEX) + void* pLexState; +#endif +} file_ref_t; + +extern file_ref_t* pCurrentFile; + +int yywarn(char* str); +void yyerror(char* msg, ...); +int setup(void); +int include_file(char* fn, void* pContext); +void GetErrorCounts(int* nError, int* nWarning); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/list.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/list.h new file mode 100644 index 0000000000000..89855484ec89a --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/list.h @@ -0,0 +1,46 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef LIST_H +#define LIST_H +typedef struct LIST_NODE_T { + struct LIST_NODE_T* pNext; + struct LIST_NODE_T* pPrev; + void* pData; +} node_t; + +typedef struct LIST_T { + struct LIST_NODE_T* head; + struct LIST_NODE_T* tail; + struct LIST_NODE_T* pCurrent; + int (*pSortFunc)(const void* pD1, const void* pD2); + int nMembers; + int nFlags; +} list_t; + +/* list_t flags */ +#define L_FL_HEAD 0x01 /* add at head */ +#define L_FL_TAIL 0x02 /* add at tail */ +#define L_FL_SORT 0x04 /* create sorted list */ + +#define length(list) list->nMembers + +list_t* makeList( + int nFlags, + int (*pSortFunc)(const void* pD1, const void* pD2)); +list_t* addList(list_t* pList, void* pData); +void* findList(list_t* pList, void* pData); +void* removeItem(list_t* pList, int bFromHead); +void* getHead(list_t* pList); +void* getTail(list_t* pList); +void* getNext(list_t* pList); +void* getItem(list_t* pList, int nIndex); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/load.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/load.h new file mode 100644 index 0000000000000..6c3b4977bd534 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/load.h @@ -0,0 +1,18 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef LOAD_H +#define LOAD_H +#include "tables.h" +void load_init(void); +void load_close(void); +int create_table(int nTable); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/mathops.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/mathops.h new file mode 100644 index 0000000000000..7f4d0edc6941b --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/mathops.h @@ -0,0 +1,29 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#define OP_PLUS 0x00001 +#define OP_MINUS 0x00002 +#define OP_MULT 0x00004 +#define OP_DIV 0x00008 +#define OP_MOD 0x00010 +#define OP_XOR 0x00020 +#define OP_PAREN 0x00040 +#define OP_BRACKET 0x00080 +#define OP_NEST 0x00100 /* a --> (a) */ +#define OP_NEG 0x00200 +#define OP_ADDR 0x00400 /* get an address */ +#define OP_PTR 0x00800 /* reference through a pointer */ +#define OP_FUNC 0x01000 /* user function/macro */ +#define OP_UNIQUE 0x02000 /* built in functions start here */ +#define OP_TEXT 0x04000 +#define OP_RANDOM 0x08000 +#define OP_RANGE 0x10000 +#define OP_USER 0x20000 /* user defined function */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/misc.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/misc.h new file mode 100644 index 0000000000000..8c7d26ab5643c --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/misc.h @@ -0,0 +1,29 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef MISC_H +#define MISC_H +int prep_direct(int dialect); +int close_direct(int dialect); +int pick_tbl(char* dname); +int itostr(char* dest, int i); +int char_op(char* dest, int op, char* s1, char* s2); +char* gen_text( + char* dest, + int min, + int max, + int stream, + DSDGenContext& dsdGenContext); +int int_op(int* dest, int op, int arg1, int arg2); + +char* env_config(char* var, char* dflt); +int a_rnd(int min, int max, int column, char* dest); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/nulls.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/nulls.h new file mode 100644 index 0000000000000..8c9dbcea41081 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/nulls.h @@ -0,0 +1,20 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef R_NULLCHECK_H +#define R_NULLCHECK_H + +#include "dist.h" + +int nullCheck(int nColumn, DSDGenContext& dsdGenContext); +void nullSet(ds_key_t* pDest, int nStream, DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/parallel.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/parallel.h new file mode 100644 index 0000000000000..bc86e3cc13a34 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/parallel.h @@ -0,0 +1,23 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef PARALLEL_H +#define PARALLEL_H + +int split_work( + int nTable, + ds_key_t* pkFirstRow, + ds_key_t* pkRowCount, + DSDGenContext& dsdGenContext); +int row_stop(int tbl, DSDGenContext& dsdGenContext); +int row_skip(int tbl, ds_key_t count, DSDGenContext& dsdGenContext); + +#endif /* PARALLEL_H */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/params.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/params.h new file mode 100644 index 0000000000000..62b2ff12c5357 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/params.h @@ -0,0 +1,25 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef QGEN_PARAMS_H +#define QGEN_PARAMS_H + +#include "build_support.h" +#include "r_params.h" + +#ifdef DECLARER +#else +extern option_t options[]; +extern char* params[]; +extern char* szTableNames[]; +#endif + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/permute.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/permute.h new file mode 100644 index 0000000000000..0d0c96c875fd4 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/permute.h @@ -0,0 +1,22 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +int* makePermutation( + int* pNumberSet, + int nSize, + int nStream, + DSDGenContext& dsdGenContext); +ds_key_t* makeKeyPermutation( + ds_key_t* pNumberSet, + ds_key_t nSize, + int nStream, + DSDGenContext& dsdGenContext); +#define getPermutationEntry(pPermutation, nIndex) (pPermutation[nIndex - 1] + 1) diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/porting.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/porting.h new file mode 100644 index 0000000000000..117c4a58b8559 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/porting.h @@ -0,0 +1,144 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef PORTING_H +#define PORTING_H + +#include +// #ifdef USE_STRING_H +// #include +// #else +// #include +// #endif + +#ifdef USE_VALUES_H +#include +#endif + +#ifdef USE_LIMITS_H +#include +#endif + +#ifdef USE_STDLIB_H +#include +#endif + +#ifndef WIN32 +#include +#else +#define int32_t __int32 +#define int64_t __int64 +#endif + +#ifdef WIN32 +#include +#define timeb _timeb +#define ftime _ftime +#else +#include +#endif + +#include "config.h" + +typedef HUGE_TYPE ds_key_t; + +/* + * add some functions that are not strictly ANSI standard + */ +#ifndef strdup +char* strdup(const char*); +#endif + +#ifdef WIN32 +#include +#include +#include +#include +#define random rand +#define strncasecmp _strnicmp +#define strcasecmp _stricmp +#define strdup _strdup +#define access _access +#define isatty _isatty +#define fileno _fileno +#define F_OK 0 +#define MAXINT INT_MAX +#define THREAD __declspec(thread) +#define MIN_MULTI_NODE_ROWS 100000 +#define MIN_MULTI_THREAD_ROWS 5000 +#define THREAD __declspec(thread) +/* Lines added by Chuck McDevitt for WIN32 support */ +#ifndef _POSIX_ +#ifndef S_ISREG +#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) +#define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) +#endif +#endif +#endif /* WIN32 */ + +#ifdef _MSC_VER +#pragma comment(lib, "ws2_32.lib") +#endif + +#ifdef INTERIX +#include +#define MAXINT INT_MAX +#endif /* INTERIX */ + +#ifdef AIX +#define MAXINT INT_MAX +#endif + +#ifdef MACOS +#include +#define MAXINT INT_MAX +#endif /* MACOS */ + +#define INTERNAL(m) \ + { \ + auto result = fprintf( \ + stderr, "ERROR: %s\n\tFile: %s\n\tLine: %d\n", m, __FILE__, __LINE__); \ + if (result < 0) \ + perror("sprintf failed"); \ + } + +#define OPEN_CHECK(var, path) \ + if ((var) == NULL) { \ + fprintf( \ + stderr, "Open failed for %s at %s:%d\n", path, __FILE__, __LINE__); \ + exit(1); \ + } + +#ifdef MEM_TEST +#define MALLOC_CHECK(v) \ + if (v == NULL) { \ + fprintf(stderr, "Malloc Failed at %d in %s\n", __LINE__, __FILE__); \ + exit(1); \ + } else { \ + fprintf( \ + stderr, \ + "Add (%x) %d at %d in %s\n", \ + sizeof(*v), \ + v, \ + __LINE__, \ + __FILE__); \ + } +#else +#define MALLOC_CHECK(v) \ + if (v == nullptr) { \ + int result = \ + fprintf(stderr, "Malloc Failed at %d in %s\n", __LINE__, __FILE__); \ + if (result < 0) \ + perror("fprintf failed"); \ + exit(1); \ + } +#endif /* MEM_TEST */ +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/pricing.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/pricing.h new file mode 100644 index 0000000000000..beb7ce76ec039 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/pricing.h @@ -0,0 +1,29 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef PRICING_H +#define PRICING_H +#include "decimal.h" + +typedef struct DS_LIMITS_T { + int nId; + char* szQuantity; + char* szMarkUp; + char* szDiscount; + char* szWholesale; + char* szCoupon; +} ds_limits_t; + +void set_pricing( + int nTabId, + ds_pricing_t* pPricing, + DSDGenContext& dsdGenContext); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/r_params.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/r_params.h new file mode 100644 index 0000000000000..ee631698e3588 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/r_params.h @@ -0,0 +1,53 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "dist.h" + +#ifndef R_PARAMS_H +#define R_PARAMS_H +#define OPT_NONE 0x00 +#define OPT_FLG 0x01 /* option is a flag; no parameter */ +#define OPT_INT 0x02 /* argument is an integer */ +#define OPT_STR 0x04 /* argument is a string */ +#define OPT_NOP 0x08 /* flags non-operational options */ +#define OPT_SUB 0x10 /* sub-option defined */ +#define OPT_ADV 0x20 /* advanced option */ +#define OPT_SET \ + 0x40 /* not changeable -- used for default/file/command precedence */ +#define OPT_DFLT 0x80 /* param set to non-zero default */ +#define OPT_MULTI 0x100 /* param may be set repeatedly */ +#define OPT_HIDE 0x200 /* hidden option -- not listed in usage */ +#define TYPE_MASK 0x07 +#endif +/* + * function declarations + */ +int process_options(int count, const char** args); +char* get_str(const char* var, DSDGenContext& dsdGenContext); +void set_str( + const char* param, + const char* value, + DSDGenContext& dsdGenContext); +int get_int(const char* var, DSDGenContext& dsdGenContext); +void set_int(const char* var, const char* val, DSDGenContext& dsdGenContext); +double get_dbl(const char* var, DSDGenContext& dsdGenContext); +int is_set(const char* flag, DSDGenContext& dsdGenContext); +void clr_flg(const char* flag, DSDGenContext& dsdGenContext); +int find_table(const char* szParamName, const char* tname); +char* GetParamName(int nParam, DSDGenContext& dsdGenContext); +char* GetParamValue(int nParam, DSDGenContext& dsdGenContext); +int load_param(int nParam, const char* value, DSDGenContext& dsdGenContext); +int fnd_param(const char* name, DSDGenContext& dsdGenContext); +int init_params(DSDGenContext& dsdGenContext); +int set_option(const char* pname, const char* value); +void load_params(void); +int IsIntParam(const char* szName, DSDGenContext& dsdGenContext); +int IsStrParam(const char* szName, DSDGenContext& dsdGenContext); diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/scaling.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/scaling.h new file mode 100644 index 0000000000000..7a217a6619550 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/scaling.h @@ -0,0 +1,28 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "dist.h" + +#ifndef SCALING_H +#define SCALING_H + +ds_key_t get_rowcount(int table, DSDGenContext& dsdGenContext); +ds_key_t getIDCount(int nTable, DSDGenContext& dsdGenContext); +int getUpdateID(ds_key_t* pDest, int nTable, int nColumn); +int getScaleSlot(int nTargetGB, DSDGenContext& dsdGenContext); +int getSkewedJulianDate(int nWeight, int nColumn, DSDGenContext& dsdGenContext); +ds_key_t dateScaling(int nColumn, ds_key_t jDate, DSDGenContext& dsdGenContext); +int getUpdateDate(int nTable, ds_key_t kRowcount, DSDGenContext& dsdGenContext); +void setUpdateDates(DSDGenContext& dsdGenContext); +void setUpdateScaling(int nTable, DSDGenContext& dsdGenContext); +ds_key_t getUpdateBase(int nTable, DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/scd.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/scd.h new file mode 100644 index 0000000000000..842316b9061da --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/scd.h @@ -0,0 +1,52 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef SCD_H +#define SCD_H + +#include "decimal.h" +#include "tables.h" + +extern char arBKeys[MAX_TABLE][17]; +int setSCDKeys( + int nTableID, + ds_key_t hgIndex, + char* szBKey, + ds_key_t* hgBeginDateKey, + ds_key_t* hgEndDateKey, + DSDGenContext& dsdGenContext); +ds_key_t +scd_join(int tbl, int col, ds_key_t jDate, DSDGenContext& dsdGenContext); +ds_key_t matchSCDSK( + ds_key_t kUnique, + ds_key_t jDate, + int nTable, + DSDGenContext& dsdGenContext); +ds_key_t getSKFromID(ds_key_t kID, int nColumn, DSDGenContext& dsdGenContext); +ds_key_t getFirstSK(ds_key_t kID); +/* + * handle the partial change of a history keeping record + * TODO: remove the macros in favor of straight fucntion calls + */ +#define SCD_INT 0 +#define SCD_CHAR 1 +#define SCD_DEC 2 +#define SCD_KEY 3 +#define SCD_PTR 4 +void changeSCD( + int nDataType, + void* pNewData, + void* pOldData, + int* nFlags, + int bFirst); +int validateSCD(int nTable, ds_key_t kRow, int* Permutation); +void printValidation(int nTable, ds_key_t kRow); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/skip_days.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/skip_days.h new file mode 100644 index 0000000000000..1fdc3fc8a6194 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/skip_days.h @@ -0,0 +1,22 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef R_SKIP_DAYS_H +#define R_SKIP_DAYS_H + +#include "config.h" +#include "dist.h" +#include "porting.h" + +ds_key_t +skipDays(int nTable, ds_key_t* pRemainder, DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/sparse.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/sparse.h new file mode 100644 index 0000000000000..f4305162fe1db --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/sparse.h @@ -0,0 +1,20 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "dist.h" + +int initSparseKeys( + int nTable, + DSDGenContext& dsdGenContext); /* populate the set of valid keys */ +ds_key_t randomSparseKey( + int nTable, + int nColumn, + DSDGenContext& dsdGenContext); /* select a random sparse key */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/streams.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/streams.h new file mode 100644 index 0000000000000..b7f316d939f25 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/streams.h @@ -0,0 +1,18 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +/* + * THIS IS A GENERATED FILE + * SEE COLUMNS.LIST + */ +#ifndef STREAMS_H +#define STREAMS_H +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tables.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tables.h new file mode 100644 index 0000000000000..5559c831ab761 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tables.h @@ -0,0 +1,92 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +/* + * THIS IS A GENERATED FILE + * SEE COLUMNS.LIST + */ +#ifndef TABLES_H +#define TABLES_H +#define CALL_CENTER 0 +#define CATALOG_PAGE 1 +#define CATALOG_RETURNS 2 +#define CATALOG_SALES 3 +#define CUSTOMER 4 +#define CUSTOMER_ADDRESS 5 +#define CUSTOMER_DEMOGRAPHICS 6 +#define DATET 7 +#define HOUSEHOLD_DEMOGRAPHICS 8 +#define INCOME_BAND 9 +#define INVENTORY 10 +#define ITEM 11 +#define PROMOTION 12 +#define REASON 13 +#define SHIP_MODE 14 +#define STORE 15 +#define STORE_RETURNS 16 +#define STORE_SALES 17 +#define TIME 18 +#define WAREHOUSE 19 +#define WEB_PAGE 20 +#define WEB_RETURNS 21 +#define WEB_SALES 22 +#define WEB_SITE 23 +#define DBGEN_VERSION 24 +#define S_BRAND 25 +#define S_CUSTOMER_ADDRESS 26 +#define S_CALL_CENTER 27 +#define S_CATALOG 28 +#define S_CATALOG_ORDER 29 +#define S_CATALOG_ORDER_LINEITEM 30 +#define S_CATALOG_PAGE 31 +#define S_CATALOG_PROMOTIONAL_ITEM 32 +#define S_CATALOG_RETURNS 33 +#define S_CATEGORY 34 +#define S_CLASS 35 +#define S_COMPANY 36 +#define S_CUSTOMER 37 +#define S_DIVISION 38 +#define S_INVENTORY 39 +#define S_ITEM 40 +#define S_MANAGER 41 +#define S_MANUFACTURER 42 +#define S_MARKET 43 +#define S_PRODUCT 44 +#define S_PROMOTION 45 +#define S_PURCHASE 46 +#define S_PURCHASE_LINEITEM 47 +#define S_REASON 48 +#define S_STORE 49 +#define S_STORE_PROMOTIONAL_ITEM 50 +#define S_STORE_RETURNS 51 +#define S_SUBCATEGORY 52 +#define S_SUBCLASS 53 +#define S_WAREHOUSE 54 +#define S_WEB_ORDER 55 +#define S_WEB_ORDER_LINEITEM 56 +#define S_WEB_PAGE 57 +#define S_WEB_PROMOTIONAL_ITEM 58 +#define S_WEB_RETURNS 59 +#define S_WEB_SITE 60 +#define S_ZIPG 61 +#define PSEUDO_TABLE_START 62 +/* PSEUDO TABLES from here on; used in hierarchies */ +#define ITEM_BRAND 62 +#define ITEM_CLASS 63 +#define ITEM_CATEGORY 64 +#define DIVISIONS 65 +#define COMPANY 66 +#define CONCURRENT_WEB_SITES 67 +#define ACTIVE_CITIES 68 +#define ACTIVE_COUNTIES 69 +#define ACTIVE_STATES 70 +#define MAX_TABLE 70 +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tdef_functions.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tdef_functions.h new file mode 100644 index 0000000000000..f75685c529460 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tdef_functions.h @@ -0,0 +1,46 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef TDEF_FUNCTIONS_H +#define TDEF_FUNCTIONS_H +#include "dist.h" +#include "tables.h" + +/* +* table functions. +* NOTE: This table contains the function declarations in the table descriptions; +it must be kept in sync with the +* declararions of assocaited constants, found in tdefs.h + +*/ +typedef struct TABLE_FUNC_T { + char* name; /* -- name of the table; */ + int (*builder)( + void*, + ds_key_t, + DSDGenContext& dsdGenContext); /* -- function to prep output */ + int (*loader[2])(void*); /* -- functions to present output */ + /* -- data validation function */ + int (*validate)(int nTable, ds_key_t kRow, int* Permutation); +} table_func_t; + +extern table_func_t w_tdef_funcs[MAX_TABLE]; +extern table_func_t s_tdef_funcs[MAX_TABLE]; +extern table_func_t* tdef_funcs; + +int validateGeneric(int nTable, ds_key_t kRow, int* Permutation); +int validateSCD(int nTable, ds_key_t kRow, int* Permutation); + +#endif /* TDEF_FUNCTIONS_H */ +extern table_func_t s_tdef_funcs[]; +extern table_func_t w_tdef_funcs[]; + +table_func_t* getTdefFunctionsByNumber(int nTable); diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tdefs.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tdefs.h new file mode 100644 index 0000000000000..5da454bbfc4d2 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tdefs.h @@ -0,0 +1,30 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef TDEFS_H +#define TDEFS_H + +#include +#include "columns.h" +#include "dist.h" +#include "tables.h" +#include "tdef_functions.h" + +#define tdefIsFlagSet(t, f) (tdefs[t].flags & f) +ds_key_t GetRowcountByName(char* szName, DSDGenContext& dsdGenContext); +int GetTableNumber(char* szName, DSDGenContext& dsdGenContext); +const char* getTableNameByID(int id, DSDGenContext& dsdGenContext); +int getTableFromColumn(int id, DSDGenContext& dsdGenContext); +int initSpareKeys(int id, DSDGenContext& dsdGenContext); +tdef* getSimpleTdefsByNumber(int nTable, DSDGenContext& dsdGenContext); +tdef* getTdefsByNumber(int nTable, DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/template.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/template.h new file mode 100644 index 0000000000000..e1d1cb36f2e98 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/template.h @@ -0,0 +1,46 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef TEMPLATE_H +#define TEMPLATE_H +#include "StringBuffer.h" +#include "expr.h" +#include "list.h" +#include "substitution.h" + +/* Replacement flags */ +#define REPL_FL_NONE 0x0001 /* no effect on result set size */ +#define REPL_FL_MORE 0x0002 /* likely to increase result set size */ +#define REPL_FL_LESS 0x0004 /* likely to decrease result set size */ + +typedef struct TEMPLATE_T { + char* name; + int index; + int flags; + list_t* SubstitutionList; + list_t* SegmentList; + list_t* DistList; +} template_t; +#define QT_INIT 0x0001 + +extern template_t* pCurrentQuery; + +void PrintQuery(FILE* fp, template_t* t); +int AddQuerySegment(template_t* pQuery, char* szSQL); +int AddQuerySubstitution( + template_t* Query, + char* szSubName, + int nUse, + int nSubPart); +int AddSubstitution(template_t* t, char* s, expr_t* pExpr); +int SetSegmentFlag(template_t* Query, int nSegmentNumber, int nFlag); +substitution_t* FindSubstitution(template_t* t, char* stmt, int* nUse); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tpcds.idx.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tpcds.idx.h new file mode 100644 index 0000000000000..40ce44ac44886 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/tpcds.idx.h @@ -0,0 +1,266 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +/* +THIS IS AN AUTOMATICALLY GENERATED FILE +DO NOT EDIT + +See distcomp.c for details +*/ + +/* aliases for values/weights in the first_names distribution */ +#define first_names_name 1 +#define first_names_male 1 +#define first_names_female 2 +#define first_names_unified 3 + +/* aliases for values/weights in the last_names distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the calendar distribution */ +#define calendar_day_seq 1 +#define calendar_month_name 2 +#define calendar_date 3 +#define calendar_season 4 +#define calendar_month_num 5 +#define calendar_quarter 6 +#define calendar_fom 7 +#define calendar_holiday 8 +#define calendar_uniform 1 +#define calendar_uniform_leap 2 +#define calendar_sales 3 +#define calendar_sales_leap 4 +#define calendar_returns 5 +#define calendar_returns_leap 6 +#define calendar_skewed 7 +#define calendar_low 8 +#define calendar_medium 9 +#define calendar_high 10 + +/* aliases for values/weights in the week_info distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the fips_county distribution */ +#define fips_county_fips 1 +#define fips_county_county 2 +#define fips_county_st 3 +#define fips_county_state 4 +#define fips_county_zone 5 +#define fips_county_gmt 6 +#define fips_county_uniform 1 +#define fips_county_population 2 +#define fips_county_tz 3 +#define fips_county_tz90 4 +#define fips_county_tz9 5 +#define fips_county_tz1 6 + +/* aliases for values/weights in the street_names distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the street_type distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the adjectives distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the adverbs distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the articles distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the nouns distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the prepositions distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the verbs distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the auxiliaries distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the terminators distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the sentences distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the syllables distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the cities distribution */ +#define cities_name 1 +#define cities_usgs 1 +#define cities_uniform 2 +#define cities_large 3 +#define cities_medium 4 +#define cities_small 5 +#define cities_unified 6 + +/* aliases for values/weights in the categories distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the women_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the men_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the children_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the shoe_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the music_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the jewelry_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the home_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the sport_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the book_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the electronic_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the sizes distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the units distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the container distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the colors distribution */ +#define colors_name 1 +#define colors_uniform 1 +#define colors_skewed 2 +#define colors_low 3 +#define colors_medium 4 +#define colors_high 5 + +/* aliases for values/weights in the brand_syllables distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the i_current_price distribution */ +#define i_current_price_index 1 +#define i_current_price_low_bound 2 +#define i_current_price_high_bound 3 +#define i_current_price_skew 1 +#define i_current_price_high 2 +#define i_current_price_medium 3 +#define i_current_price_low 4 + +/* aliases for values/weights in the i_manufact_id distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the i_manager_id distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the rowcounts distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the gender distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the marital_status distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the education distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the purchase_band distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the buy_potential distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the credit_rating distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the income_band distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the dependent_count distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the vehicle_count distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the promo_purpose distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the return_reasons distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the store_type distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the geography_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the divisions distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the stores distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the hours distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the call_centers distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the call_center_hours distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the call_center_class distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the salutations distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the ship_mode_code distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the ship_mode_type distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the ship_mode_carrier distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the web_page_use distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the web_page_type distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the catalog_page_type distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the location_type distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the top_domains distribution */ +/* NONE DEFINED */ + +/* aliases for values/weights in the countries distribution */ +/* NONE DEFINED */ diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_call_center.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_call_center.h new file mode 100644 index 0000000000000..5d6da36840bc7 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_call_center.h @@ -0,0 +1,31 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_CALL_CENTER_H +#define W_CALL_CENTER_H +#include "address.h" +#include "constants.h" +#include "date.h" +#include "decimal.h" +#include "dist.h" +#include "pricing.h" + +#define MIN_CC_TAX_PERCENTAGE "0.00" +#define MAX_CC_TAX_PERCENTAGE "0.12" + +int mk_w_call_center( + void* pDest, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); +int pr_w_call_center(void* pSrc); +int ld_w_call_center(void* r); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_catalog_page.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_catalog_page.h new file mode 100644 index 0000000000000..0241eacdab3b2 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_catalog_page.h @@ -0,0 +1,24 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef CATALOG_PAGE_H +#define CATALOG_PAGE_H + +#include "constants.h" +#include "dist.h" +#include "porting.h" + +int mk_w_catalog_page( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_catalog_returns.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_catalog_returns.h new file mode 100644 index 0000000000000..3233f75d2973e --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_catalog_returns.h @@ -0,0 +1,23 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_CATALOG_RETURNS_H +#define W_CATALOG_RETURNS_H + +#include "dist.h" +#include "pricing.h" + +int mk_w_catalog_returns( + void* row, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_catalog_sales.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_catalog_sales.h new file mode 100644 index 0000000000000..9a30c0c8c0c95 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_catalog_sales.h @@ -0,0 +1,27 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_CATALOG_SALES_H +#define W_CATALOG_SALES_H + +#include "dist.h" +#include "pricing.h" + +int mk_w_catalog_sales( + void* info_arr, + ds_key_t index, + DSDGenContext& dsdGenContext); +int vld_w_catalog_sales( + int nTable, + ds_key_t kRow, + int* Permutation, + DSDGenContext& dsdGenContext); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_customer.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_customer.h new file mode 100644 index 0000000000000..e069b44062f69 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_customer.h @@ -0,0 +1,24 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_CUSTOMER_H +#define W_CUSTOMER_H + +#include "constants.h" +#include "dist.h" +#include "porting.h" + +int mk_w_customer( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_customer_address.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_customer_address.h new file mode 100644 index 0000000000000..cc0c9638e6404 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_customer_address.h @@ -0,0 +1,24 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_CUSTOMER_ADDRESS_H +#define W_CUSTOMER_ADDRESS_H +#include "address.h" +#include "constants.h" +#include "dist.h" +#include "porting.h" + +int mk_w_customer_address( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_customer_demographics.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_customer_demographics.h new file mode 100644 index 0000000000000..1cc223313d367 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_customer_demographics.h @@ -0,0 +1,30 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_CUSTOMER_DEMOGRAPHICS_H +#define W_CUSTOMER_DEMOGRAPHICS_H + +#include "dist.h" +#include "porting.h" + +/*** +*** CD_xxx Customer Demographcis Defines +***/ +#define CD_MAX_CHILDREN 7 +#define CD_MAX_EMPLOYED 7 +#define CD_MAX_COLLEGE 7 + +int mk_w_customer_demographics( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_datetbl.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_datetbl.h new file mode 100644 index 0000000000000..875063671b395 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_datetbl.h @@ -0,0 +1,28 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ +/* + * DATE table structure + */ +#ifndef W_DATETBL_H +#define W_DATETBL_H + +#include "constants.h" +#include "dist.h" +#include "porting.h" + +int mk_w_date(void* info_arr, ds_key_t kIndex, DSDGenContext& dsdGenContext); + +int vld_w_date( + int nTable, + ds_key_t kRow, + int* Permutation, + DSDGenContext& dsdGenContext); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_household_demographics.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_household_demographics.h new file mode 100644 index 0000000000000..1f41e957fbe83 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_household_demographics.h @@ -0,0 +1,23 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_HOUSEHOLD_DEMOGRAPHICS_H +#define W_HOUSEHOLD_DEMOGRAPHICS_H + +#include "dist.h" +#include "porting.h" + +int mk_w_household_demographics( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_income_band.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_income_band.h new file mode 100644 index 0000000000000..1bf9f0bc52a6e --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_income_band.h @@ -0,0 +1,18 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "dist.h" +#include "porting.h" + +int mk_w_income_band( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_inventory.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_inventory.h new file mode 100644 index 0000000000000..2d46bdd91b59c --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_inventory.h @@ -0,0 +1,20 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "dist.h" +#include "porting.h" + +int mk_w_inventory( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); + +ds_key_t sc_w_inventory(int nScale, DSDGenContext& dsdGenContext); diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_item.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_item.h new file mode 100644 index 0000000000000..a8dbef459dd0f --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_item.h @@ -0,0 +1,30 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_ITEM_H +#define W_ITEM_H + +#include "constants.h" +#include "decimal.h" +#include "porting.h" + +#define I_PROMO_PERCENTAGE \ + 20 /* percent of items that have associated promotions */ +#define MIN_ITEM_MARKDOWN_PCT "0.30" +#define MAX_ITEM_MARKDOWN_PCT "0.90" + +int mk_w_item(void* info_arr, ds_key_t kIndex, DSDGenContext& dsdGenContext); +int vld_w_item( + int nTable, + ds_key_t kRow, + int* Permutation, + DSDGenContext& dsdGenContext); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_promotion.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_promotion.h new file mode 100644 index 0000000000000..b7e0eb67eca0c --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_promotion.h @@ -0,0 +1,24 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_PROMOTION_H +#define W_PROMOTION_H + +#include "constants.h" +#include "decimal.h" +#include "porting.h" + +int mk_w_promotion( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_reason.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_reason.h new file mode 100644 index 0000000000000..08edca765d7c9 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_reason.h @@ -0,0 +1,21 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_REASON_H +#define W_REASON_H + +#include "constants.h" +#include "dist.h" +#include "porting.h" + +int mk_w_reason(void* info_arr, ds_key_t kIndex, DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_ship_mode.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_ship_mode.h new file mode 100644 index 0000000000000..ca169d130dba6 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_ship_mode.h @@ -0,0 +1,23 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_SHIP_MODE_H +#define W_SHIP_MODE_H + +#include "constants.h" +#include "dist.h" +#include "porting.h" + +int mk_w_ship_mode( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_store.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_store.h new file mode 100644 index 0000000000000..a914fb5ff0715 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_store.h @@ -0,0 +1,20 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_STORE_H +#define W_STORE_H + +#include "address.h" +#include "decimal.h" + +int mk_w_store(void* info_arr, ds_key_t kIndex, DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_store_returns.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_store_returns.h new file mode 100644 index 0000000000000..30553c7dfc008 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_store_returns.h @@ -0,0 +1,23 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_STORE_RETURNS_H +#define W_STORE_RETURNS_H +#include "decimal.h" +#include "pricing.h" + +#define SR_SAME_CUSTOMER 80 + +int mk_w_store_returns( + void* row, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_store_sales.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_store_sales.h new file mode 100644 index 0000000000000..62a48b076eed9 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_store_sales.h @@ -0,0 +1,27 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_STORE_SALES_H +#define W_STORE_SALES_H + +#include "constants.h" +#include "pricing.h" + +int mk_w_store_sales( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); +int vld_w_store_sales( + int nTable, + ds_key_t kRow, + int* Permutation, + DSDGenContext& dsdGenContext); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_timetbl.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_timetbl.h new file mode 100644 index 0000000000000..69b633efd2e19 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_timetbl.h @@ -0,0 +1,24 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +/* + * TIME table structure + */ +#ifndef W_TIME_TBL_H +#define W_TIME_TBL_H + +#include "constants.h" +#include "dist.h" +#include "porting.h" + +int mk_w_time(void* info_arr, ds_key_t kIndex, DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_warehouse.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_warehouse.h new file mode 100644 index 0000000000000..9979c622b1a5f --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_warehouse.h @@ -0,0 +1,23 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_WAREHOUSE_H +#define W_WAREHOUSE_H + +#include "address.h" +#include "porting.h" + +int mk_w_warehouse( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_page.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_page.h new file mode 100644 index 0000000000000..a75f27cb7f519 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_page.h @@ -0,0 +1,19 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "constants.h" +#include "dist.h" +#include "porting.h" + +int mk_w_web_page( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_returns.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_returns.h new file mode 100644 index 0000000000000..6456400556185 --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_returns.h @@ -0,0 +1,19 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "dist.h" +#include "porting.h" +#ifndef W_WEB_RETURNS_H +#define W_WEB_RETURNS_H + +int mk_w_web_returns(void* row, ds_key_t kIndex, DSDGenContext& dsdGenContext); + +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_sales.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_sales.h new file mode 100644 index 0000000000000..3e24d422aa48b --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_sales.h @@ -0,0 +1,38 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#include "porting.h" +#include "pricing.h" + +/*** +*** WS_xxx Web Sales Defines +***/ +#define WS_QUANTITY_MAX "100" +#define WS_MARKUP_MAX "2.00" +#define WS_DISCOUNT_MAX "1.00" +#define WS_WHOLESALE_MAX "100.00" +#define WS_COUPON_MAX "0.50" +#define WS_GIFT_PCT \ + 7 /* liklihood that a purchase is shipped to someone else \ + */ +#define WS_ITEMS_PER_ORDER 9 /* number of lineitems in an order */ +#define WS_MIN_SHIP_DELAY 1 /* time between order date and ship date */ +#define WS_MAX_SHIP_DELAY 120 + +int mk_w_web_sales( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); +int vld_web_sales( + int nTable, + ds_key_t kRow, + int* Permutation, + DSDGenContext& dsdGenContext); diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_site.h b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_site.h new file mode 100644 index 0000000000000..dfb8e8e4ac46a --- /dev/null +++ b/presto-native-execution/presto_cpp/external/dsdgen/include/dsdgen-c/w_web_site.h @@ -0,0 +1,26 @@ +/* + * Copyright owned by the Transaction Processing Performance Council. + * + * A copy of the license is included under external/dsdgen/LICENSE + * in this repository. + * + * You may not use this file except in compliance with the License. + * + * THE TPC SOFTWARE IS AVAILABLE WITHOUT CHARGE FROM TPC. + */ + +#ifndef W_WEB_SITE_H +#define W_WEB_SITE_H + +#include "address.h" +#include "constants.h" +#include "decimal.h" + +#define WEB_MIN_TAX_PERCENTAGE "0.00" +#define WEB_MAX_TAX_PERCENTAGE "0.12" + +int mk_w_web_site( + void* info_arr, + ds_key_t kIndex, + DSDGenContext& dsdGenContext); +#endif diff --git a/presto-native-execution/presto_cpp/external/dsdgen/include/tpcds.idx b/presto-native-execution/presto_cpp/external/dsdgen/include/tpcds.idx new file mode 100644 index 0000000000000..0f49b70e574e8 Binary files /dev/null and b/presto-native-execution/presto_cpp/external/dsdgen/include/tpcds.idx differ diff --git a/presto-native-execution/presto_cpp/main/CMakeLists.txt b/presto-native-execution/presto_cpp/main/CMakeLists.txt index b00fee32927b6..afb985d394ea1 100644 --- a/presto-native-execution/presto_cpp/main/CMakeLists.txt +++ b/presto-native-execution/presto_cpp/main/CMakeLists.txt @@ -14,6 +14,7 @@ add_subdirectory(types) add_subdirectory(http) add_subdirectory(common) add_subdirectory(thrift) +add_subdirectory(connectors) add_library( presto_server_lib @@ -106,6 +107,9 @@ add_executable(presto_server PrestoMain.cpp) # TODO: Fix these errors. target_link_libraries(presto_server presto_server_lib velox_hive_connector velox_tpch_connector) +if(PRESTO_ENABLE_TPCDS_CONNECTOR) + target_link_libraries(presto_server presto_tpcds_connector) +endif() if(PRESTO_ENABLE_REMOTE_FUNCTIONS) add_library(presto_server_remote_function JsonSignatureParser.cpp diff --git a/presto-native-execution/presto_cpp/main/PrestoServer.cpp b/presto-native-execution/presto_cpp/main/PrestoServer.cpp index 1f316144bbfce..1b16d23324a2a 100644 --- a/presto-native-execution/presto_cpp/main/PrestoServer.cpp +++ b/presto-native-execution/presto_cpp/main/PrestoServer.cpp @@ -26,6 +26,7 @@ #include "presto_cpp/main/common/ConfigReader.h" #include "presto_cpp/main/common/Counters.h" #include "presto_cpp/main/common/Utils.h" +#include "presto_cpp/main/connectors/tpcds/TpcdsConnector.h" #include "presto_cpp/main/http/HttpConstants.h" #include "presto_cpp/main/http/filters/AccessLogFilter.h" #include "presto_cpp/main/http/filters/HttpEndpointLatencyFilter.h" @@ -71,6 +72,10 @@ #include "presto_cpp/main/RemoteFunctionRegisterer.h" #endif +#ifdef PRESTO_ENABLE_TPCDS_CONNECTOR +#include "presto_cpp/main/connectors/tpcds/TpcdsConnector.h" +#endif + #ifdef __linux__ // Required by BatchThreadFactory #include @@ -276,6 +281,10 @@ void PrestoServer::run() { std::make_unique("system")); registerPrestoToVeloxConnector( std::make_unique("$system@system")); +#ifdef PRESTO_ENABLE_TPCDS_CONNECTOR + registerPrestoToVeloxConnector( + std::make_unique("tpcds")); +#endif velox::exec::OutputBufferManager::initialize({}); initializeVeloxMemory(); @@ -1176,6 +1185,14 @@ void PrestoServer::registerConnectorFactories() { velox::connector::registerConnectorFactory( std::make_shared()); } +#ifdef PRESTO_ENABLE_TPCDS_CONNECTOR + if (!velox::connector::hasConnectorFactory( + presto::connector::tpcds::TpcdsConnectorFactory:: + kTpcdsConnectorName)) { + velox::connector::registerConnectorFactory( + std::make_shared()); + } +#endif } std::vector PrestoServer::registerConnectors( diff --git a/presto-native-execution/presto_cpp/main/connectors/CMakeLists.txt b/presto-native-execution/presto_cpp/main/connectors/CMakeLists.txt new file mode 100644 index 0000000000000..0af6eca9075d2 --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# Licensed 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. + +if(PRESTO_ENABLE_TPCDS_CONNECTOR) + add_subdirectory(tpcds) +endif() diff --git a/presto-native-execution/presto_cpp/main/connectors/tpcds/CMakeLists.txt b/presto-native-execution/presto_cpp/main/connectors/tpcds/CMakeLists.txt new file mode 100644 index 0000000000000..2c6d344b59cdc --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/tpcds/CMakeLists.txt @@ -0,0 +1,66 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# Licensed 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. + +cmake_policy(SET CMP0079 NEW) + +project(TPCDS) + +add_library(presto_tpcds_connector OBJECT TpcdsConnector.cpp) +target_link_libraries(presto_tpcds_connector velox_connector tpcds_gen fmt::fmt) + +# Without this hack, there are multiple link errors similar to the one below +# only on GCC. "undefined reference to `vtable for +# velox::connector::tpcds::TpcdsTableHandle`. TODO: Fix this hack. +target_link_libraries(velox_exec_test_lib presto_tpcds_connector) + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wno-deprecated-declarations -Wno-writable-strings + -Wno-missing-field-initializers) +endif() + +# This stringop-overflow warning seems to have lots of false positives and has +# been the source of a lot of compiler bug reports (e.g. +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578), which causes +# parquet-amalgamation.cpp to fail to compile. For now, we disable this warning +# on the affected compiler (GCC). +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + add_compile_options(-Wno-stringop-overflow -Wno-write-strings) +endif() + +# Add subdirectories +add_subdirectory(${CMAKE_SOURCE_DIR}/presto_cpp/external/dsdgen/dsdgen-c build) + +# Generate tpcds_idx.hpp +set(INPUT_FILE tpcds.idx) +set(OUTPUT_FILE tpcds_idx.hpp) +set(WORKING_DIR ${CMAKE_SOURCE_DIR}/presto_cpp/external/dsdgen/include/) + +add_custom_command( + OUTPUT ${WORKING_DIR}/${OUTPUT_FILE} + COMMAND xxd -i -c 16 ${INPUT_FILE} > ${OUTPUT_FILE} + DEPENDS ${WORKING_DIR}/${INPUT_FILE} + COMMENT "Generating ${OUTPUT_FILE} from ${INPUT_FILE}" + WORKING_DIRECTORY ${WORKING_DIR}) + +add_custom_target(generate_tpcds_idx ALL DEPENDS ${WORKING_DIR}/${OUTPUT_FILE}) +add_dependencies(dsdgen_c generate_tpcds_idx) + +add_library(append_info OBJECT utils/append_info-c.cpp) +target_link_libraries(append_info velox_vector_test_lib Folly::folly xsimd) +target_link_libraries(dsdgen_c append_info) + +add_library(tpcds_gen TpcdsGen.cpp DSDGenIterator.cpp) +target_include_directories(tpcds_gen PUBLIC dsdgen/include) +target_link_libraries(tpcds_gen velox_memory velox_vector dsdgen_c append_info + fmt::fmt) diff --git a/presto-native-execution/presto_cpp/main/connectors/tpcds/DSDGenIterator.cpp b/presto-native-execution/presto_cpp/main/connectors/tpcds/DSDGenIterator.cpp new file mode 100644 index 0000000000000..b2122edaae954 --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/tpcds/DSDGenIterator.cpp @@ -0,0 +1,91 @@ +/* + * Licensed 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. + */ + +#include "presto_cpp/main/connectors/tpcds/DSDGenIterator.h" +#include "presto_cpp/external/dsdgen/include/dsdgen-c/dist.h" +#include "presto_cpp/external/dsdgen/include/dsdgen-c/genrand.h" +#include "presto_cpp/external/dsdgen/include/dsdgen-c/parallel.h" +#include "presto_cpp/external/dsdgen/include/dsdgen-c/params.h" +#include "presto_cpp/external/dsdgen/include/dsdgen-c/scaling.h" +#include "presto_cpp/external/dsdgen/include/dsdgen-c/tdefs.h" +#include "velox/common/base/Exceptions.h" + +using namespace facebook::velox; + +namespace facebook::presto::connector::tpcds { + +void initializeDSDgen( + double scale, + int32_t parallel, + int32_t child, + DSDGenContext& dsdGenContext) { + dsdGenContext.Reset(); + resetCountCount(); + + std::string scaleStr = std::to_string(scale); + set_str("SCALE", scaleStr.c_str(), dsdGenContext); + std::string parallelStr = std::to_string(parallel); + set_str("PARALLEL", parallelStr.c_str(), dsdGenContext); + std::string childStr = std::to_string(child); + set_str("CHILD", childStr.c_str(), dsdGenContext); + + init_rand(dsdGenContext); // no random numbers without this +} + +DSDGenIterator::DSDGenIterator( + double scaleFactor, + int32_t parallel, + int32_t child) { + tableDefs_.resize(DBGEN_VERSION); // there are 24 TPC-DS tables + VELOX_CHECK_GE(scaleFactor, 0.0, "Tpcds scale factor must be non-negative"); + initializeDSDgen(scaleFactor, parallel, child, dsdgenCtx_); +} + +void DSDGenIterator::initializeTable( + const std::vector& children, + int table_id) { + auto tdef = getSimpleTdefsByNumber(table_id, dsdgenCtx_); + TpcdsTableDef table_def; + table_def.name = tdef->name; + table_def.fl_child = tdef->flags & FL_CHILD ? 1 : 0; + table_def.fl_small = tdef->flags & FL_SMALL ? 1 : 0; + table_def.first_column = tdef->nFirstColumn; + table_def.children = children; + table_def.dsdGenContext = &dsdgenCtx_; + tableDefs_[table_id] = std::make_unique(table_def); +} + +std::vector>& DSDGenIterator::getTableDefs() { + return tableDefs_; +}; + +tpcds_builder_func DSDGenIterator::getTDefFunctionByNumber(int table_id) { + auto table_funcs = getTdefFunctionsByNumber(table_id); + return table_funcs->builder; +} + +void DSDGenIterator::initTableOffset(int32_t table_id, size_t offset) { + row_skip(table_id, offset, dsdgenCtx_); +} +void DSDGenIterator::genRow(int32_t table_id, size_t index) { + auto builder_func = getTDefFunctionByNumber(table_id); + builder_func((void*)&tableDefs_, index, dsdgenCtx_); + row_stop(table_id, dsdgenCtx_); +} + +int64_t DSDGenIterator::getRowCount(int32_t table) { + return get_rowcount(table, dsdgenCtx_); +} + +} // namespace facebook::presto::connector::tpcds diff --git a/presto-native-execution/presto_cpp/main/connectors/tpcds/DSDGenIterator.h b/presto-native-execution/presto_cpp/main/connectors/tpcds/DSDGenIterator.h new file mode 100644 index 0000000000000..3a2641f6434bc --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/tpcds/DSDGenIterator.h @@ -0,0 +1,71 @@ +/* + * Licensed 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. + */ + +#pragma once + +#include + +#include "presto_cpp/external/dsdgen/include/dsdgen-c/dist.h" +#include "presto_cpp/main/connectors/tpcds/utils/append_info-c.h" + +using namespace facebook::velox; +namespace facebook::presto::connector::tpcds { + +typedef int64_t ds_key_t; + +typedef int (*tpcds_builder_func)(void*, ds_key_t, DSDGenContext& dsdgenCtx); + +void initializeDSDgen( + double scale, + int32_t parallel, + int32_t child, + DSDGenContext& dsdGenContext); + +/// This class exposes a thread-safe and reproducible iterator over TPC-DS +/// synthetically generated data, backed by DSDGEN. +class DSDGenIterator { + public: + explicit DSDGenIterator(double scaleFactor, int32_t parallel, int32_t child); + + /// Initializes the table definition and the table schema. + void initializeTable(const std::vector& children, int table); + + /// Returns a vector of all the table definitions. + std::vector>& getTableDefs(); + + // Before generating records using the gen*() functions below, call the + // initTableOffset(int32_t table_id, size_t offset) function to correctly + // initialize the seed given the offset to be generated. + // table_id corresponds to the table that needs to be generated and offset + // specifies the number of rows to skip before using the gen*() functions. + void initTableOffset(int32_t table_id, size_t offset); + + /// Generate different types of records. + // table_id corresponds to the table that is to be generated and row is the + // row to be generated. + void genRow(int32_t table_id, size_t row); + + /// Gets the row count for a table. + ds_key_t getRowCount(int32_t table_id); + + // Gets the metadata for a table, which hold information about the mk_*() + // functions responsible for generating the data. + tpcds_builder_func getTDefFunctionByNumber(int table_id); + + protected: + DSDGenContext dsdgenCtx_; + std::vector> tableDefs_; +}; + +} // namespace facebook::presto::connector::tpcds diff --git a/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsConnector.cpp b/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsConnector.cpp new file mode 100644 index 0000000000000..15fe9c9bcce0e --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsConnector.cpp @@ -0,0 +1,190 @@ +/* + * Licensed 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. + */ + +#include "presto_cpp/main/connectors/tpcds/TpcdsConnector.h" +#include "presto_cpp/main/connectors/tpcds/DSDGenIterator.h" +#include "presto_cpp/presto_protocol/connector/tpcds/TpcdsConnectorProtocol.h" + +using namespace ::facebook::velox; +namespace facebook::presto::connector::tpcds { + +using facebook::presto::connector::tpcds::Table; + +std::string TpcdsTableHandle::toString() const { + return fmt::format( + "table: {}, scale factor: {}", toTableName(table_), scaleFactor_); +} + +TpcdsDataSource::TpcdsDataSource( + const std::shared_ptr& outputType, + const std::shared_ptr& tableHandle, + const std::unordered_map< + std::string, + std::shared_ptr>& columnHandles, + velox::memory::MemoryPool* FOLLY_NONNULL pool) + : pool_(pool) { + auto tpcdsTableHandle = + std::dynamic_pointer_cast(tableHandle); + VELOX_CHECK_NOT_NULL( + tpcdsTableHandle, "TableHandle must be an instance of TpcdsTableHandle"); + table_ = tpcdsTableHandle->getTpcdsTable(); + scaleFactor_ = tpcdsTableHandle->getScaleFactor(); + DSDGenIterator dsdGenIterator(scaleFactor_, 1, 1); + rowCount_ = dsdGenIterator.getRowCount(static_cast(table_)); + + auto tpcdsTableSchema = getTableSchema(tpcdsTableHandle->getTpcdsTable()); + VELOX_CHECK_NOT_NULL(tpcdsTableSchema, "TpcdsSchema can't be null."); + + outputColumnMappings_.reserve(outputType->size()); + + for (const auto& outputName : outputType->names()) { + auto it = columnHandles.find(outputName); + VELOX_CHECK( + it != columnHandles.end(), + "ColumnHandle is missing for output column '{}' on table '{}'", + outputName, + toTableName(table_)); + + auto handle = std::dynamic_pointer_cast(it->second); + VELOX_CHECK_NOT_NULL( + handle, + "ColumnHandle must be an instance of TpcdsColumnHandle " + "for '{}' on table '{}'", + handle->name(), + toTableName(table_)); + + auto idx = tpcdsTableSchema->getChildIdxIfExists(handle->name()); + VELOX_CHECK( + idx != std::nullopt, + "Column '{}' not found on TPC-DS table '{}'.", + handle->name(), + toTableName(table_)); + outputColumnMappings_.emplace_back(*idx); + } + outputType_ = outputType; +} + +RowVectorPtr TpcdsDataSource::projectOutputColumns(RowVectorPtr inputVector) { + std::vector children; + children.reserve(outputColumnMappings_.size()); + + for (const auto channel : outputColumnMappings_) { + children.emplace_back(inputVector->childAt(channel)); + } + + return std::make_shared( + pool_, + outputType_, + BufferPtr(), + inputVector->size(), + std::move(children)); +} + +void TpcdsDataSource::addSplit(std::shared_ptr split) { + VELOX_CHECK_EQ( + currentSplit_, + nullptr, + "Previous split has not been processed yet. Call next() to process the split."); + currentSplit_ = std::dynamic_pointer_cast(split); + VELOX_CHECK(currentSplit_, "Wrong type of split for TpcdsDataSource."); + + size_t partSize = + std::ceil((double)rowCount_ / (double)currentSplit_->totalParts_); + + splitOffset_ = partSize * currentSplit_->partNumber_; + splitEnd_ = splitOffset_ + partSize; +} + +std::optional TpcdsDataSource::next( + uint64_t size, + velox::ContinueFuture& /*future*/) { + VELOX_CHECK_NOT_NULL( + currentSplit_, "No split to process. Call addSplit() first."); + + size_t maxRows = std::min(size, (splitEnd_ - splitOffset_)); + vector_size_t parallel = currentSplit_->totalParts_; + vector_size_t child = currentSplit_->partNumber_; + auto outputVector = genTpcdsData( + table_, maxRows, splitOffset_, pool_, scaleFactor_, parallel, child); + + // If the split is exhausted. + if (!outputVector || outputVector->size() == 0) { + currentSplit_ = nullptr; + return nullptr; + } + + // splitOffset needs to advance based on maxRows passed to getTpcdsData(), and + // not the actual number of returned rows in the output vector, as they are + // not the same for lineitem. + splitOffset_ += maxRows; + completedRows_ += outputVector->size(); + completedBytes_ += outputVector->retainedSize(); + + return projectOutputColumns(outputVector); +} + +std::unique_ptr +TpcdsPrestoToVeloxConnector::toVeloxSplit( + const protocol::ConnectorId& catalogId, + const protocol::ConnectorSplit* connectorSplit, + const protocol::SplitContext* splitContext) const { + auto tpcdsSplit = + dynamic_cast(connectorSplit); + VELOX_CHECK_NOT_NULL( + tpcdsSplit, "Unexpected split type {}", connectorSplit->_type); + return std::make_unique( + catalogId, + splitContext->cacheable, + tpcdsSplit->totalParts, + tpcdsSplit->partNumber); +} + +std::unique_ptr +TpcdsPrestoToVeloxConnector::toVeloxColumnHandle( + const protocol::ColumnHandle* column, + const TypeParser& typeParser) const { + auto tpcdsColumn = + dynamic_cast(column); + VELOX_CHECK_NOT_NULL( + tpcdsColumn, "Unexpected column handle type {}", column->_type); + return std::make_unique( + tpcdsColumn->columnName); +} + +std::unique_ptr +TpcdsPrestoToVeloxConnector::toVeloxTableHandle( + const protocol::TableHandle& tableHandle, + const VeloxExprConverter& exprConverter, + const TypeParser& typeParser, + std::unordered_map< + std::string, + std::shared_ptr>& assignments) const { + auto tpcdsLayout = + std::dynamic_pointer_cast( + tableHandle.connectorTableLayout); + VELOX_CHECK_NOT_NULL( + tpcdsLayout, + "Unexpected layout type {}", + tableHandle.connectorTableLayout->_type); + return std::make_unique( + tableHandle.connectorId, + presto::connector::tpcds::fromTableName(tpcdsLayout->table.tableName), + tpcdsLayout->table.scaleFactor); +} + +std::unique_ptr +TpcdsPrestoToVeloxConnector::createConnectorProtocol() const { + return std::make_unique(); +} +} // namespace facebook::presto::connector::tpcds diff --git a/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsConnector.h b/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsConnector.h new file mode 100644 index 0000000000000..36dd55628fab2 --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsConnector.h @@ -0,0 +1,209 @@ +/* + * Licensed 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. + */ + +#pragma once + +#include "presto_cpp/main/connectors/tpcds/TpcdsConnectorSplit.h" +#include "presto_cpp/main/connectors/tpcds/TpcdsGen.h" +#include "presto_cpp/main/types/PrestoToVeloxConnector.h" +#include "velox/connectors/Connector.h" + +using namespace facebook::velox; +using namespace facebook::velox::connector; + +namespace facebook::presto::connector::tpcds { + +class TpcdsConnector; + +// TPC-DS column handle only needs the column name (all columns are generated in +// the same way). +class TpcdsColumnHandle : public velox::connector::ColumnHandle { + public: + explicit TpcdsColumnHandle(const std::string& name) : name_(name) {} + + const std::string& name() const { + return name_; + } + + private: + const std::string name_; +}; + +// TPC-DS table handle uses the underlying enum to describe the target table. +class TpcdsTableHandle : public ConnectorTableHandle { + public: + explicit TpcdsTableHandle( + std::string connectorId, + tpcds::Table table, + double scaleFactor = 1.0) + : ConnectorTableHandle(std::move(connectorId)), + table_(table), + scaleFactor_(scaleFactor) { + VELOX_CHECK_GE(scaleFactor, 0.0, "Tpcds scale factor must be non-negative"); + } + + ~TpcdsTableHandle() override {} + + std::string toString() const override; + + tpcds::Table getTpcdsTable() const { + return table_; + } + + double getScaleFactor() const { + return scaleFactor_; + } + + private: + const tpcds::Table table_; + double scaleFactor_; +}; + +class TpcdsDataSource : public velox::connector::DataSource { + public: + TpcdsDataSource( + const std::shared_ptr& outputType, + const std::shared_ptr& + tableHandle, + const std::unordered_map< + std::string, + std::shared_ptr>& columnHandles, + velox::memory::MemoryPool* FOLLY_NONNULL pool); + + void addSplit(std::shared_ptr split) override; + + void addDynamicFilter( + column_index_t /*outputChannel*/, + const std::shared_ptr& /*filter*/) override { + VELOX_NYI("Dynamic filters not supported by TpcdsConnector."); + } + + std::optional next(uint64_t size, velox::ContinueFuture& future) + override; + + uint64_t getCompletedRows() override { + return completedRows_; + } + + uint64_t getCompletedBytes() override { + return completedBytes_; + } + + std::unordered_map runtimeStats() override { + return {}; + } + + private: + RowVectorPtr projectOutputColumns(RowVectorPtr vector); + + tpcds::Table table_; + double scaleFactor_{1.0}; + size_t rowCount_{0}; + RowTypePtr outputType_; + + // Mapping between output columns and their indices (column_index_t) in the + // dsdgen generated datasets. + std::vector outputColumnMappings_; + + std::shared_ptr currentSplit_; + + // Offset of the first row in current split. + uint64_t splitOffset_{0}; + // Offset of the last row in current split. + uint64_t splitEnd_{0}; + + size_t completedRows_{0}; + size_t completedBytes_{0}; + + memory::MemoryPool* FOLLY_NONNULL pool_; +}; + +class TpcdsConnector final : public velox::connector::Connector { + public: + TpcdsConnector( + const std::string& id, + std::shared_ptr config, + folly::Executor* FOLLY_NULLABLE /*executor*/) + : Connector(id) {} + + std::unique_ptr createDataSource( + const std::shared_ptr& outputType, + const std::shared_ptr& tableHandle, + const std::unordered_map< + std::string, + std::shared_ptr>& columnHandles, + ConnectorQueryCtx* FOLLY_NONNULL connectorQueryCtx) override final { + return std::make_unique( + outputType, + tableHandle, + columnHandles, + connectorQueryCtx->memoryPool()); + } + + std::unique_ptr createDataSink( + RowTypePtr /*inputType*/, + std::shared_ptr< + ConnectorInsertTableHandle> /*connectorInsertTableHandle*/, + ConnectorQueryCtx* /*connectorQueryCtx*/, + CommitStrategy /*commitStrategy*/) override final { + VELOX_NYI("TpcdsConnector does not support data sink."); + } +}; + +class TpcdsConnectorFactory : public ConnectorFactory { + public: + static constexpr const char* kTpcdsConnectorName{"tpcds"}; + + TpcdsConnectorFactory() : ConnectorFactory(kTpcdsConnectorName) {} + + explicit TpcdsConnectorFactory(const char* connectorName) + : ConnectorFactory(connectorName) {} + + std::shared_ptr newConnector( + const std::string& id, + std::shared_ptr config, + folly::Executor* ioExecutor = nullptr, + folly::Executor* cpuExecutor = nullptr) override { + return std::make_shared(id, config, ioExecutor); + } +}; + +class TpcdsPrestoToVeloxConnector final : public PrestoToVeloxConnector { + public: + explicit TpcdsPrestoToVeloxConnector(std::string connectorId) + : PrestoToVeloxConnector(std::move(connectorId)) {} + + std::unique_ptr toVeloxSplit( + const protocol::ConnectorId& catalogId, + const protocol::ConnectorSplit* connectorSplit, + const protocol::SplitContext* splitContext) const final; + + std::unique_ptr toVeloxColumnHandle( + const protocol::ColumnHandle* column, + const TypeParser& typeParser) const final; + + std::unique_ptr toVeloxTableHandle( + const protocol::TableHandle& tableHandle, + const VeloxExprConverter& exprConverter, + const TypeParser& typeParser, + std::unordered_map< + std::string, + std::shared_ptr>& assignments) + const final; + + std::unique_ptr createConnectorProtocol() + const final; +}; + +} // namespace facebook::presto::connector::tpcds diff --git a/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsConnectorSplit.h b/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsConnectorSplit.h new file mode 100644 index 0000000000000..76c85c402dc32 --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsConnectorSplit.h @@ -0,0 +1,73 @@ +/* + * Licensed 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. + */ + +#pragma once + +#include +#include "velox/connectors/Connector.h" + +using namespace facebook::velox; + +namespace facebook::presto::connector::tpcds { + +struct TpcdsConnectorSplit : public velox::connector::ConnectorSplit { + explicit TpcdsConnectorSplit( + const std::string& connectorId, + size_t totalParts, + size_t partNumber) + : TpcdsConnectorSplit(connectorId, true, totalParts, partNumber) {} + + TpcdsConnectorSplit( + const std::string& connectorId, + bool cacheable, + size_t totalParts, + size_t partNumber) + : ConnectorSplit(connectorId, /*splitWeight=*/0, cacheable), + totalParts_(totalParts), + partNumber_(partNumber) { + VELOX_CHECK_GE(totalParts, 1, "totalParts must be >= 1"); + VELOX_CHECK_GT(totalParts, partNumber, "totalParts must be > partNumber"); + } + + // In how many parts the generated TPC-DS table will be segmented, roughly + // `rowCount / totalParts` + const vector_size_t totalParts_{1}; + + // Which of these parts will be read by this split. + const vector_size_t partNumber_{0}; +}; + +} // namespace facebook::presto::connector::tpcds + +template <> +struct fmt::formatter + : formatter { + auto format( + facebook::presto::connector::tpcds::TpcdsConnectorSplit s, + format_context& ctx) { + return formatter::format(s.toString(), ctx); + } +}; + +template <> +struct fmt::formatter< + std::shared_ptr> + : formatter { + auto format( + std::shared_ptr + s, + format_context& ctx) { + return formatter::format(s->toString(), ctx); + } +}; diff --git a/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsGen.cpp b/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsGen.cpp new file mode 100644 index 0000000000000..83a4f1769291a --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsGen.cpp @@ -0,0 +1,946 @@ +/* + * Licensed 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. + */ + +#include "presto_cpp/main/connectors/tpcds/TpcdsGen.h" +#include "presto_cpp/main/connectors/tpcds/DSDGenIterator.h" +#include "velox/vector/ComplexVector.h" + +using namespace facebook::velox; +namespace facebook::presto::connector::tpcds { + +namespace { +size_t getVectorSize(size_t rowCount, size_t maxRows, size_t offset) { + if (offset >= rowCount) { + return 0; + } + return std::min(rowCount - offset, maxRows); +} + +std::vector allocateChildVectors( + const RowTypePtr& type, + size_t vectorSize, + memory::MemoryPool* pool) { + std::vector vector; + vector.reserve(type->size()); + + for (const auto& childType : type->children()) { + vector.emplace_back(BaseVector::create(childType, vectorSize, pool)); + } + return vector; +} + +RowVectorPtr genTpcdsRowVector( + int32_t tableId, + memory::MemoryPool* pool, + RowTypePtr rowType, + std::vector>& tableDef) { + auto rowCount = tableDef[tableId]->rowIndex; + for (auto& child : tableDef[tableId]->children) { + child->resize(rowCount); + } + + return std::make_shared( + pool, + rowType, + BufferPtr(nullptr), + rowCount, + std::move(tableDef[tableId]->children)); +} + +RowVectorPtr genTpcdsTableData( + Table table, + memory::MemoryPool* pool, + size_t maxRows, + size_t offset, + double scaleFactor, + int32_t parallel, + int32_t child) { + // Create schema and allocate vectors. + auto rowType = getTableSchema(table); + auto table_id = static_cast(table); + DSDGenIterator dsdGenIterator(scaleFactor, parallel, child); + size_t vectorSize = + getVectorSize(dsdGenIterator.getRowCount(table_id), maxRows, offset); + auto children = allocateChildVectors(rowType, vectorSize, pool); + dsdGenIterator.initTableOffset(table_id, offset); + dsdGenIterator.initializeTable(children, table_id); + auto& tableDef = dsdGenIterator.getTableDefs(); + for (size_t i = 0; i < vectorSize; ++i) { + dsdGenIterator.genRow(table_id, i + offset + 1); + } + return std::make_shared( + pool, + rowType, + BufferPtr(nullptr), + vectorSize, + std::move(tableDef[table_id]->children)); +} + +RowVectorPtr genTpcdsParentAndChildTable( + memory::MemoryPool* pool, + size_t maxRows, + size_t offset, + double scaleFactor, + int32_t parallel, + int32_t child, + Table parentTable, + Table childTable, + bool childTableCall) { + // Whenever a call to generate a table which is either marked as a + // parent or a child is requested, both the child and parent tables + // need to be populated. + + auto parentTableType = getTableSchema(parentTable); + DSDGenIterator dsdGenIterator(scaleFactor, parallel, child); + size_t parentTableVectorSize = getVectorSize( + dsdGenIterator.getRowCount(static_cast(parentTable)), + maxRows, + offset); + + size_t parentTableUpperBound = parentTableVectorSize * 16; + auto children = + allocateChildVectors(parentTableType, parentTableUpperBound, pool); + + auto childTableType = getTableSchema(childTable); + auto childChildren = + allocateChildVectors(childTableType, parentTableUpperBound, pool); + + auto parentTableId = static_cast(parentTable); + auto childTableId = static_cast(childTable); + + dsdGenIterator.initTableOffset(parentTableId, offset); + dsdGenIterator.initializeTable(children, parentTableId); + dsdGenIterator.initializeTable(childChildren, childTableId); + auto& tableDef = dsdGenIterator.getTableDefs(); + for (size_t i = 0; i < parentTableVectorSize; ++i) { + dsdGenIterator.genRow(parentTableId, i + offset + 1); + } + if (childTableCall) { + return genTpcdsRowVector(childTableId, pool, childTableType, tableDef); + } else { + return genTpcdsRowVector(parentTableId, pool, parentTableType, tableDef); + } +} +} // namespace + +static const RowTypePtr callCenterType = ROW( + {"cc_call_center_sk", "cc_call_center_id", + "cc_rec_start_date", "cc_rec_end_date", + "cc_closed_date_sk", "cc_open_date_sk", + "cc_name", "cc_class", + "cc_employees", "cc_sq_ft", + "cc_hours", "cc_manager", + "cc_mkt_id", "cc_mkt_class", + "cc_mkt_desc", "cc_market_manager", + "cc_division", "cc_division_name", + "cc_company", "cc_company_name", + "cc_street_number", "cc_street_name", + "cc_street_type", "cc_suite_number", + "cc_city", "cc_county", + "cc_state", "cc_zip", + "cc_country", "cc_gmt_offset", + "cc_tax_percentage"}, + {BIGINT(), VARCHAR(), DATE(), DATE(), INTEGER(), INTEGER(), + VARCHAR(), VARCHAR(), INTEGER(), INTEGER(), VARCHAR(), VARCHAR(), + INTEGER(), VARCHAR(), VARCHAR(), VARCHAR(), INTEGER(), VARCHAR(), + INTEGER(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), + VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), DECIMAL(5, 2), + DECIMAL(5, 2)}); + +static const RowTypePtr catalogPageType = + ROW({"cp_catalog_page_sk", + "cp_catalog_page_id", + "cp_start_date_sk", + "cp_end_date_sk", + "cp_department", + "cp_catalog_number", + "cp_catalog_page_number", + "cp_description", + "cp_type"}, + {BIGINT(), + VARCHAR(), + INTEGER(), + INTEGER(), + VARCHAR(), + INTEGER(), + INTEGER(), + VARCHAR(), + VARCHAR()}); + +static const RowTypePtr catalogReturnsType = ROW( + {"cr_returned_date_sk", + "cr_returned_time_sk", + "cr_item_sk", + "cr_refunded_customer_sk", + "cr_refunded_cdemo_sk", + "cr_refunded_hdemo_sk", + "cr_refunded_addr_sk", + "cr_returning_customer_sk", + "cr_returning_cdemo_sk", + "cr_returning_hdemo_sk", + "cr_returning_addr_sk", + "cr_call_center_sk", + "cr_catalog_page_sk", + "cr_ship_mode_sk", + "cr_warehouse_sk", + "cr_reason_sk", + "cr_order_number", + "cr_return_quantity", + "cr_return_amount", + "cr_return_tax", + "cr_return_amt_inc_tax", + "cr_fee", + "cr_return_ship_cost", + "cr_refunded_cash", + "cr_reversed_charge", + "cr_store_credit", + "cr_net_loss"}, + {BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), INTEGER(), DECIMAL(7, 2), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2)}); + +static const RowTypePtr catalogSalesType = ROW( + {"cs_sold_date_sk", + "cs_sold_time_sk", + "cs_ship_date_sk", + "cs_bill_customer_sk", + "cs_bill_cdemo_sk", + "cs_bill_hdemo_sk", + "cs_bill_addr_sk", + "cs_ship_customer_sk", + "cs_ship_cdemo_sk", + "cs_ship_hdemo_sk", + "cs_ship_addr_sk", + "cs_call_center_sk", + "cs_catalog_page_sk", + "cs_ship_mode_sk", + "cs_warehouse_sk", + "cs_item_sk", + "cs_promo_sk", + "cs_order_number", + "cs_quantity", + "cs_wholesale_cost", + "cs_list_price", + "cs_sales_price", + "cs_ext_discount_amt", + "cs_ext_sales_price", + "cs_ext_wholesale_cost", + "cs_ext_list_price", + "cs_ext_tax", + "cs_coupon_amt", + "cs_ext_ship_cost", + "cs_net_paid", + "cs_net_paid_inc_tax", + "cs_net_paid_inc_ship", + "cs_net_paid_inc_ship_tax", + "cs_net_profit"}, + {BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), INTEGER(), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2)}); + +static const RowTypePtr customerType = ROW( + { + "c_customer_sk", + "c_customer_id", + "c_current_cdemo_sk", + "c_current_hdemo_sk", + "c_current_addr_sk", + "c_first_shipto_date_sk", + "c_first_sales_date_sk", + "c_salutation", + "c_first_name", + "c_last_name", + "c_preferred_cust_flag", + "c_birth_day", + "c_birth_month", + "c_birth_year", + "c_birth_country", + "c_login", + "c_email_address", + "c_last_review_date_sk", + }, + { + BIGINT(), + VARCHAR(), + BIGINT(), + BIGINT(), + BIGINT(), + BIGINT(), + BIGINT(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + INTEGER(), + INTEGER(), + INTEGER(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + BIGINT(), + }); + +static const RowTypePtr customerAddressType = + ROW({"ca_address_sk", + "ca_address_id", + "ca_street_number", + "ca_street_name", + "ca_street_type", + "ca_suite_number", + "ca_city", + "ca_county", + "ca_state", + "ca_zip", + "ca_country", + "ca_gmt_offset", + "ca_location_type"}, + {BIGINT(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + DECIMAL(5, 2), + VARCHAR()}); + +static const RowTypePtr customerDemographicsType = + ROW({"cd_demo_sk", + "cd_gender", + "cd_marital_status", + "cd_education_status", + "cd_purchase_estimate", + "cd_credit_rating", + "cd_dep_count", + "cd_dep_employed_count", + "cd_dep_college_count"}, + {BIGINT(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + INTEGER(), + VARCHAR(), + INTEGER(), + INTEGER(), + INTEGER()}); + +static const RowTypePtr dateDimType = ROW( + { + "d_date_sk", + "d_date_id", + "d_date", + "d_month_seq", + "d_week_seq", + "d_quarter_seq", + "d_year", + "d_dow", + "d_moy", + "d_dom", + "d_qoy", + "d_fy_year", + "d_fy_quarter_seq", + "d_fy_week_seq", + "d_day_name", + "d_quarter_name", + "d_holiday", + "d_weekend", + "d_following_holiday", + "d_first_dom", + "d_last_dom", + "d_same_day_ly", + "d_same_day_lq", + "d_current_day", + "d_current_week", + "d_current_month", + "d_current_quarter", + "d_current_year", + }, + { + BIGINT(), VARCHAR(), DATE(), INTEGER(), INTEGER(), INTEGER(), + INTEGER(), INTEGER(), INTEGER(), INTEGER(), INTEGER(), INTEGER(), + INTEGER(), INTEGER(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), + VARCHAR(), INTEGER(), INTEGER(), INTEGER(), INTEGER(), VARCHAR(), + VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), + }); + +static const RowTypePtr householdDemographicsType = + ROW({"hd_demo_sk", + "hd_income_band_sk", + "hd_buy_potential", + "hd_dep_count", + "hd_vehicle_count"}, + {BIGINT(), BIGINT(), VARCHAR(), INTEGER(), INTEGER()}); + +static const RowTypePtr incomeBandType = + ROW({"ib_income_band_sk", "ib_lower_bound", "ib_upper_bound"}, + {BIGINT(), INTEGER(), INTEGER()}); + +static const RowTypePtr inventoryType = ROW( + {"inv_date_sk", "inv_item_sk", "inv_warehouse_sk", "inv_quantity_on_hand"}, + {BIGINT(), BIGINT(), BIGINT(), INTEGER()}); + +static const RowTypePtr itemType = ROW( + {"i_item_sk", "i_item_id", "i_rec_start_date", "i_rec_end_date", + "i_item_desc", "i_current_price", "i_wholesale_cost", "i_brand_id", + "i_brand", "i_class_id", "i_class", "i_category_id", + "i_category", "i_manufact_id", "i_manufact", "i_size", + "i_formulation", "i_color", "i_units", "i_container", + "i_manager_id", "i_product_name"}, + {BIGINT(), VARCHAR(), DATE(), DATE(), VARCHAR(), DECIMAL(7, 2), + DECIMAL(7, 2), INTEGER(), VARCHAR(), INTEGER(), VARCHAR(), INTEGER(), + VARCHAR(), INTEGER(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), + VARCHAR(), VARCHAR(), INTEGER(), VARCHAR()}); + +static const RowTypePtr promotionType = + ROW({"p_promo_sk", + "p_promo_id", + "p_start_date_sk", + "p_end_date_sk", + "p_item_sk", + "p_cost", + "p_response_targe", + "p_promo_name", + "p_channel_dmail", + "p_channel_email", + "p_channel_catalog", + "p_channel_tv", + "p_channel_radio", + "p_channel_press", + "p_channel_event", + "p_channel_demo", + "p_channel_details", + "p_purpose", + "p_discount_active"}, + {BIGINT(), + VARCHAR(), + BIGINT(), + BIGINT(), + BIGINT(), + DECIMAL(15, 2), + INTEGER(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR()}); + +static const RowTypePtr reasonType = + ROW({"r_reason_sk", "r_reason_id", "r_reason_desc"}, + {BIGINT(), VARCHAR(), VARCHAR()}); + +static const RowTypePtr shipModeType = + ROW({"sm_ship_mode_sk", + "sm_ship_mode_id", + "sm_type", + "sm_code", + "sm_carrier", + "sm_contract"}, + {BIGINT(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR()}); + +static const RowTypePtr storeType = ROW( + { + "s_store_sk", + "s_store_id", + "s_rec_start_date", + "s_rec_end_date", + "s_closed_date_sk", + "s_store_name", + "s_number_employees", + "s_floor_space", + "s_hours", + "s_manager", + "s_market_id", + "s_geography_class", + "s_market_desc", + "s_market_manager", + "s_division_id", + "s_division_name", + "s_company_id", + "s_company_name", + "s_street_number", + "s_street_name", + "s_street_type", + "s_suite_number", + "s_city", + "s_county", + "s_state", + "s_zip", + "s_country", + "s_gmt_offset", + "s_tax_precentage", + }, + { + BIGINT(), VARCHAR(), DATE(), DATE(), BIGINT(), + VARCHAR(), INTEGER(), INTEGER(), VARCHAR(), VARCHAR(), + INTEGER(), VARCHAR(), VARCHAR(), VARCHAR(), INTEGER(), + VARCHAR(), INTEGER(), VARCHAR(), VARCHAR(), VARCHAR(), + VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), + VARCHAR(), VARCHAR(), DECIMAL(5, 2), DECIMAL(5, 2), + }); + +static const RowTypePtr storeReturnsType = + ROW({"sr_returned_date_sk", + "sr_return_time_sk", + "sr_item_sk", + "sr_customer_sk", + "sr_cdemo_sk", + "sr_hdemo_sk", + "sr_addr_sk", + "sr_store_sk", + "sr_reason_sk", + "sr_ticket_number", + "sr_return_quantity", + "sr_return_amt", + "sr_return_tax", + "sr_return_amt_inc_tax", + "sr_fee", + "sr_return_ship_cost", + "sr_refunded_cash", + "sr_reversed_charge", + "sr_store_credit", + "sr_net_loss"}, + {BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), INTEGER(), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2)}); + +static const RowTypePtr storeSalesType = ROW( + {"ss_sold_date_sk", "ss_sold_time_sk", "ss_item_sk", + "ss_customer_sk", "ss_cdemo_sk", "ss_hdemo_sk", + "ss_addr_sk", "ss_store_sk", "ss_promo_sk", + "ss_ticket_number", "ss_quantity", "ss_wholesale_cost", + "ss_list_price", "ss_sales_price", "ss_ext_discount_amt", + "ss_ext_sales_price", "ss_ext_wholesale_cost", "ss_ext_list_price", + "ss_ext_tax", "ss_coupon_amt", "ss_net_paid", + "ss_net_paid_inc_tax", "ss_net_profit"}, + {BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + INTEGER(), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2)}); + +static const RowTypePtr timeDimType = + ROW({"t_time_sk", + "t_time_id", + "t_time", + "t_hour", + "t_minute", + "t_second", + "t_am_pm", + "t_shift", + "t_sub_shift", + "t_meal_time"}, + {BIGINT(), + VARCHAR(), + INTEGER(), + INTEGER(), + INTEGER(), + INTEGER(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR()}); + +static const RowTypePtr warehouseType = + ROW({"w_warehouse_sk", + "w_warehouse_id", + "w_warehouse_name", + "w_warehouse_sq_ft", + "w_street_number", + "w_street_name", + "w_street_type", + "w_suite_number", + "w_city", + "w_county", + "w_state", + "w_zip", + "w_country", + "w_gmt_offset"}, + {BIGINT(), + VARCHAR(), + VARCHAR(), + INTEGER(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + VARCHAR(), + DECIMAL(5, 2)}); + +static const RowTypePtr webPageType = + ROW({"wp_web_page_sk", + "wp_web_page_id", + "wp_rec_start_date", + "wp_rec_end_date", + "wp_creation_date_sk", + "wp_access_date_sk", + "wp_autogen_flag", + "wp_customer_sk", + "wp_url", + "wp_type", + "wp_char_count", + "wp_link_count", + "wp_image_count", + "wp_max_ad_count"}, + {BIGINT(), + VARCHAR(), + DATE(), + DATE(), + BIGINT(), + BIGINT(), + VARCHAR(), + BIGINT(), + VARCHAR(), + VARCHAR(), + INTEGER(), + INTEGER(), + INTEGER(), + INTEGER()}); + +static const RowTypePtr webReturnsType = ROW( + {"wr_returned_date_sk", + "wr_returned_time_sk", + "wr_item_sk", + "wr_refunded_customer_sk", + "wr_refunded_cdemo_sk", + "wr_refunded_hdemo_sk", + "wr_refunded_addr_sk", + "wr_returning_customer_sk", + "wr_returning_cdemo_sk", + "wr_returning_hdemo_sk", + "wr_returning_addr_sk", + "wr_web_page_sk", + "wr_reason_sk", + "wr_order_number", + "wr_return_quantity", + "wr_return_amt", + "wr_return_tax", + "wr_return_amt_inc_tax", + "wr_fee", + "wr_return_ship_cost", + "wr_refunded_cash", + "wr_reversed_charge", + "wr_account_credit", + "wr_net_loss"}, + {BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), BIGINT(), INTEGER(), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2)}); + +static const RowTypePtr webSalesType = ROW( + {"ws_sold_date_sk", + "ws_sold_time_sk", + "ws_ship_date_sk", + "ws_item_sk", + "ws_bill_customer_sk", + "ws_bill_cdemo_sk", + "ws_bill_hdemo_sk", + "ws_bill_addr_sk", + "ws_ship_customer_sk", + "ws_ship_cdemo_sk", + "ws_ship_hdemo_sk", + "ws_ship_addr_sk", + "ws_web_page_sk", + "ws_web_site_sk", + "ws_ship_mode_sk", + "ws_warehouse_sk", + "ws_promo_sk", + "ws_order_number", + "ws_quantity", + "ws_wholesale_cost", + "ws_list_price", + "ws_sales_price", + "ws_ext_discount_amt", + "ws_ext_sales_price", + "ws_ext_wholesale_cost", + "ws_ext_list_price", + "ws_ext_tax", + "ws_coupon_amt", + "ws_ext_ship_cost", + "ws_net_paid", + "ws_net_paid_inc_tax", + "ws_net_paid_inc_ship", + "ws_net_paid_inc_ship_tax", + "ws_net_profit"}, + {BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), BIGINT(), BIGINT(), + BIGINT(), BIGINT(), BIGINT(), INTEGER(), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), + DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2), DECIMAL(7, 2)}); + +static const RowTypePtr websiteType = ROW( + {"web_site_sk", "web_site_id", "web_rec_start_date", + "web_rec_end_date", "web_name", "web_open_date_sk", + "web_close_date_sk", "web_class", "web_manager", + "web_mkt_id", "web_mkt_class", "web_mkt_desc", + "web_market_manager", "web_company_id", "web_company_name", + "web_street_number", "web_street_name", "web_street_type", + "web_suite_number", "web_city", "web_county", + "web_state", "web_zip", "web_country", + "web_gmt_offset", "web_tax_percentage"}, + {BIGINT(), VARCHAR(), DATE(), DATE(), VARCHAR(), BIGINT(), + BIGINT(), VARCHAR(), VARCHAR(), INTEGER(), VARCHAR(), VARCHAR(), + VARCHAR(), INTEGER(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), + VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), VARCHAR(), + DECIMAL(5, 2), DECIMAL(5, 2)}); + +const RowTypePtr getTableSchema(Table table) { + switch (table) { + case Table::TBL_CALL_CENTER: + return callCenterType; + case Table::TBL_CATALOG_PAGE: + return catalogPageType; + case Table::TBL_CATALOG_RETURNS: + return catalogReturnsType; + case Table::TBL_CATALOG_SALES: + return catalogSalesType; + case Table::TBL_CUSTOMER: + return customerType; + case Table::TBL_CUSTOMER_ADDRESS: + return customerAddressType; + case Table::TBL_CUSTOMER_DEMOGRAPHICS: + return customerDemographicsType; + case Table::TBL_DATE_DIM: + return dateDimType; + case Table::TBL_HOUSEHOLD_DEMOGRAPHICS: + return householdDemographicsType; + case Table::TBL_INCOME_BAND: + return incomeBandType; + case Table::TBL_INVENTORY: + return inventoryType; + case Table::TBL_ITEM: + return itemType; + case Table::TBL_PROMOTION: + return promotionType; + case Table::TBL_REASON: + return reasonType; + case Table::TBL_SHIP_MODE: + return shipModeType; + case Table::TBL_STORE: + return storeType; + case Table::TBL_STORE_RETURNS: + return storeReturnsType; + case Table::TBL_STORE_SALES: + return storeSalesType; + case Table::TBL_TIME_DIM: + return timeDimType; + case Table::TBL_WAREHOUSE: + return warehouseType; + case Table::TBL_WEB_PAGE: + return webPageType; + case Table::TBL_WEB_RETURNS: + return webReturnsType; + case Table::TBL_WEB_SALES: + return webSalesType; + case Table::TBL_WEB_SITE: + return websiteType; + default: + VELOX_UNREACHABLE(); + } +} + +std::string toTableName(Table table) { + switch (table) { + case Table::TBL_CALL_CENTER: + return "call_center"; + case Table::TBL_CATALOG_PAGE: + return "catalog_page"; + case Table::TBL_CATALOG_RETURNS: + return "catalog_returns"; + case Table::TBL_CATALOG_SALES: + return "catalog_sales"; + case Table::TBL_CUSTOMER: + return "customer"; + case Table::TBL_CUSTOMER_ADDRESS: + return "customer_address"; + case Table::TBL_CUSTOMER_DEMOGRAPHICS: + return "customer_demographics"; + case Table::TBL_DATE_DIM: + return "date_dim"; + case Table::TBL_HOUSEHOLD_DEMOGRAPHICS: + return "household_demographics"; + case Table::TBL_INCOME_BAND: + return "income_band"; + case Table::TBL_INVENTORY: + return "inventory"; + case Table::TBL_ITEM: + return "item"; + case Table::TBL_PROMOTION: + return "promotion"; + case Table::TBL_REASON: + return "reason"; + case Table::TBL_SHIP_MODE: + return "ship_mode"; + case Table::TBL_STORE: + return "store"; + case Table::TBL_STORE_RETURNS: + return "store_returns"; + case Table::TBL_STORE_SALES: + return "store_sales"; + case Table::TBL_TIME_DIM: + return "time_dim"; + case Table::TBL_WAREHOUSE: + return "warehouse"; + case Table::TBL_WEB_PAGE: + return "web_page"; + case Table::TBL_WEB_RETURNS: + return "web_returns"; + case Table::TBL_WEB_SALES: + return "web_sales"; + case Table::TBL_WEB_SITE: + return "web_site"; + default: + VELOX_UNREACHABLE(); + } +} + +Table fromTableName(const std::string_view& tableName) { + static const std::unordered_map map{ + {"call_center", Table::TBL_CALL_CENTER}, + {"catalog_page", Table::TBL_CATALOG_PAGE}, + {"catalog_returns", Table::TBL_CATALOG_RETURNS}, + {"catalog_sales", Table::TBL_CATALOG_SALES}, + {"customer", Table::TBL_CUSTOMER}, + {"customer_address", Table::TBL_CUSTOMER_ADDRESS}, + {"customer_demographics", Table::TBL_CUSTOMER_DEMOGRAPHICS}, + {"date_dim", Table::TBL_DATE_DIM}, + {"household_demographics", Table::TBL_HOUSEHOLD_DEMOGRAPHICS}, + {"income_band", Table::TBL_INCOME_BAND}, + {"inventory", Table::TBL_INVENTORY}, + {"item", Table::TBL_ITEM}, + {"promotion", Table::TBL_PROMOTION}, + {"reason", Table::TBL_REASON}, + {"ship_mode", Table::TBL_SHIP_MODE}, + {"store", Table::TBL_STORE}, + {"store_returns", Table::TBL_STORE_RETURNS}, + {"store_sales", Table::TBL_STORE_SALES}, + {"time_dim", Table::TBL_TIME_DIM}, + {"warehouse", Table::TBL_WAREHOUSE}, + {"web_page", Table::TBL_WEB_PAGE}, + {"web_returns", Table::TBL_WEB_RETURNS}, + {"web_sales", Table::TBL_WEB_SALES}, + {"web_site", Table::TBL_WEB_SITE}, + }; + + auto it = map.find(tableName); + if (it != map.end()) { + return it->second; + } + throw std::invalid_argument( + fmt::format("Invalid TPC-DS table name: '{}'", tableName)); +} + +RowVectorPtr genTpcdsData( + Table table, + size_t maxRows, + size_t offset, + memory::MemoryPool* pool, + double scaleFactor, + int32_t parallel, + int32_t child) { + switch (table) { + Table parentTable, childTable; + case Table::TBL_CATALOG_RETURNS: + case Table::TBL_CATALOG_SALES: + parentTable = Table::TBL_CATALOG_SALES; + childTable = Table::TBL_CATALOG_RETURNS; + return genTpcdsParentAndChildTable( + pool, + maxRows, + offset, + scaleFactor, + parallel, + child, + parentTable, + childTable, + table == childTable); + case Table::TBL_WEB_RETURNS: + case Table::TBL_WEB_SALES: + parentTable = Table::TBL_WEB_SALES; + childTable = Table::TBL_WEB_RETURNS; + return genTpcdsParentAndChildTable( + pool, + maxRows, + offset, + scaleFactor, + parallel, + child, + parentTable, + childTable, + table == childTable); + case Table::TBL_STORE_RETURNS: + case Table::TBL_STORE_SALES: + parentTable = Table::TBL_STORE_SALES; + childTable = Table::TBL_STORE_RETURNS; + return genTpcdsParentAndChildTable( + pool, + maxRows, + offset, + scaleFactor, + parallel, + child, + parentTable, + childTable, + table == childTable); + case Table::TBL_CALL_CENTER: + case Table::TBL_CATALOG_PAGE: + case Table::TBL_CUSTOMER: + case Table::TBL_CUSTOMER_ADDRESS: + case Table::TBL_CUSTOMER_DEMOGRAPHICS: + case Table::TBL_DATE_DIM: + case Table::TBL_HOUSEHOLD_DEMOGRAPHICS: + case Table::TBL_INCOME_BAND: + case Table::TBL_INVENTORY: + case Table::TBL_ITEM: + case Table::TBL_PROMOTION: + case Table::TBL_REASON: + case Table::TBL_SHIP_MODE: + case Table::TBL_STORE: + case Table::TBL_TIME_DIM: + case Table::TBL_WAREHOUSE: + case Table::TBL_WEB_PAGE: + case Table::TBL_WEB_SITE: + return genTpcdsTableData( + table, pool, maxRows, offset, scaleFactor, parallel, child); + default: + VELOX_UNREACHABLE(); + } +} +} // namespace facebook::presto::connector::tpcds diff --git a/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsGen.h b/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsGen.h new file mode 100644 index 0000000000000..a2df6a340e213 --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/tpcds/TpcdsGen.h @@ -0,0 +1,99 @@ +/* + * Licensed 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. + */ + +#pragma once + +#include "velox/common/memory/Memory.h" + +namespace facebook::velox { +class RowVector; +using RowVectorPtr = std::shared_ptr; +class RowType; +using RowTypePtr = std::shared_ptr; +} // namespace facebook::velox + +namespace facebook::presto::connector::tpcds { + +/// This file uses TPC-DS DSDGEN to generate data encoded using Velox Vectors. + +enum class Table : uint8_t { + TBL_CALL_CENTER, + TBL_CATALOG_PAGE, + TBL_CATALOG_RETURNS, + TBL_CATALOG_SALES, + TBL_CUSTOMER, + TBL_CUSTOMER_ADDRESS, + TBL_CUSTOMER_DEMOGRAPHICS, + TBL_DATE_DIM, + TBL_HOUSEHOLD_DEMOGRAPHICS, + TBL_INCOME_BAND, + TBL_INVENTORY, + TBL_ITEM, + TBL_PROMOTION, + TBL_REASON, + TBL_SHIP_MODE, + TBL_STORE, + TBL_STORE_RETURNS, + TBL_STORE_SALES, + TBL_TIME_DIM, + TBL_WAREHOUSE, + TBL_WEB_PAGE, + TBL_WEB_RETURNS, + TBL_WEB_SALES, + TBL_WEB_SITE +}; + +static const auto tables = { + tpcds::Table::TBL_CALL_CENTER, + tpcds::Table::TBL_CATALOG_PAGE, + tpcds::Table::TBL_CATALOG_RETURNS, + tpcds::Table::TBL_CATALOG_SALES, + tpcds::Table::TBL_CUSTOMER, + tpcds::Table::TBL_CUSTOMER_ADDRESS, + tpcds::Table::TBL_CUSTOMER_DEMOGRAPHICS, + tpcds::Table::TBL_DATE_DIM, + tpcds::Table::TBL_HOUSEHOLD_DEMOGRAPHICS, + tpcds::Table::TBL_INCOME_BAND, + tpcds::Table::TBL_INVENTORY, + tpcds::Table::TBL_ITEM, + tpcds::Table::TBL_PROMOTION, + tpcds::Table::TBL_REASON, + tpcds::Table::TBL_SHIP_MODE, + tpcds::Table::TBL_STORE, + tpcds::Table::TBL_STORE_RETURNS, + tpcds::Table::TBL_STORE_SALES, + tpcds::Table::TBL_TIME_DIM, + tpcds::Table::TBL_WAREHOUSE, + tpcds::Table::TBL_WEB_PAGE, + tpcds::Table::TBL_WEB_RETURNS, + tpcds::Table::TBL_WEB_SALES, + tpcds::Table::TBL_WEB_SITE}; + +/// Returns table name as a string. +std::string toTableName(Table table); + +/// Returns the schema (RowType) for a particular TPC-DS table. +const velox::RowTypePtr getTableSchema(Table table); + +Table fromTableName(const std::string_view& tableName); + +velox::RowVectorPtr genTpcdsData( + Table table, + size_t maxRows, + size_t offset, + velox::memory::MemoryPool* pool, + double scaleFactor, + int32_t parallel, + int32_t child); +} // namespace facebook::presto::connector::tpcds diff --git a/presto-native-execution/presto_cpp/main/connectors/tpcds/utils/append_info-c.cpp b/presto-native-execution/presto_cpp/main/connectors/tpcds/utils/append_info-c.cpp new file mode 100644 index 0000000000000..72edd76819806 --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/tpcds/utils/append_info-c.cpp @@ -0,0 +1,158 @@ +/* + * Licensed 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. + */ + +#include "append_info-c.h" + +#include +#include "presto_cpp/external/dsdgen/include/dsdgen-c/append_info.h" +#include "presto_cpp/external/dsdgen/include/dsdgen-c/config.h" +#include "presto_cpp/external/dsdgen/include/dsdgen-c/date.h" +#include "presto_cpp/external/dsdgen/include/dsdgen-c/nulls.h" +#include "presto_cpp/external/dsdgen/include/dsdgen-c/porting.h" +#include "velox/vector/FlatVector.h" + +using namespace facebook::velox; +using namespace facebook::presto::connector::tpcds; +append_info* append_info_get(void* info_list, int table_id) { + auto& append_vector = + *((std::vector>*)info_list); + return (append_info*)append_vector[table_id].get(); +} + +bool facebook::presto::connector::tpcds::TpcdsTableDef::IsNull(int32_t column) { + return nullCheck(column, *dsdGenContext); +} + +void append_row_start(append_info info) { + auto append_info = (TpcdsTableDef*)info; +} + +void append_row_end(append_info info) { + auto append_info = (TpcdsTableDef*)info; + append_info->colIndex %= append_info->children.size(); + append_info->rowIndex++; +} + +void append_varchar( + int32_t column, + append_info info, + const char* value, + bool fillEmptyStringAsNull) { + auto append_info = (TpcdsTableDef*)info; + if (((append_info->IsNull(column)) || (!value) || (*value == '\0')) && + (fillEmptyStringAsNull)) { + append_info->children[append_info->colIndex]->setNull( + append_info->rowIndex, true); + } else { + append_info->children[append_info->colIndex] + ->asFlatVector() + ->set(append_info->rowIndex, value); + } + append_info->colIndex++; +} + +void append_varchar( + int32_t column, + append_info info, + std::string value, + bool fillEmptyStringAsNull) { + append_varchar(column, info, value.data(), fillEmptyStringAsNull); +} + +void append_key(int32_t column, append_info info, int64_t value) { + auto append_info = (TpcdsTableDef*)info; + if (append_info->IsNull(column) || value < 0) { + append_info->children[append_info->colIndex]->setNull( + append_info->rowIndex, true); + } else { + append_info->children[append_info->colIndex]->asFlatVector()->set( + append_info->rowIndex, value); + } + append_info->colIndex++; +} + +void append_integer(int32_t column, append_info info, int32_t value) { + auto append_info = (TpcdsTableDef*)info; + if (append_info->IsNull(column)) { + append_info->children[append_info->colIndex]->setNull( + append_info->rowIndex, true); + } else { + append_info->children[append_info->colIndex]->asFlatVector()->set( + append_info->rowIndex, value); + } + append_info->colIndex++; +} + +void append_boolean(int32_t column, append_info info, int32_t value) { + auto append_info = (TpcdsTableDef*)info; + if (append_info->IsNull(column)) { + append_info->children[append_info->colIndex]->setNull( + append_info->rowIndex, true); + } else { + append_info->children[append_info->colIndex]->asFlatVector()->set( + append_info->rowIndex, value != 0); + } + append_info->colIndex++; +} + +// value is a Julian date +// FIXME: direct int conversion, offsets should be constant +void append_date(int32_t column, append_info info, int64_t value) { + auto append_info = (TpcdsTableDef*)info; + if (append_info->IsNull(column) || value < 0) { + append_info->children[append_info->colIndex]->setNull( + append_info->rowIndex, true); + } else { + date_t dTemp; + jtodt(&dTemp, (int)value); + auto stringDate = + fmt::format("{}-{}-{}", dTemp.year, dTemp.month, dTemp.day); + auto date = DATE()->toDays(stringDate); + append_info->children[append_info->colIndex]->asFlatVector()->set( + append_info->rowIndex, date); + } + append_info->colIndex++; +} + +void append_decimal(int32_t column, append_info info, decimal_t* val) { + auto append_info = (TpcdsTableDef*)info; + if (append_info->IsNull(column)) { + append_info->children[append_info->colIndex]->setNull( + append_info->rowIndex, true); + } else { + auto type = append_info->children[append_info->colIndex]->type(); + if (type->isShortDecimal()) { + append_info->children[append_info->colIndex] + ->asFlatVector() + ->set(append_info->rowIndex, val->number); + } else { + append_info->children[append_info->colIndex] + ->asFlatVector() + ->set(append_info->rowIndex, val->number); + } + } + append_info->colIndex++; +} + +void append_integer_decimal(int32_t column, append_info info, int32_t value) { + auto append_info = (TpcdsTableDef*)info; + if (append_info->IsNull(column)) { + append_info->children[append_info->colIndex]->setNull( + append_info->rowIndex, true); + } else { + append_info->children[append_info->colIndex]->asFlatVector()->set( + append_info->rowIndex, (int64_t)value * 100); + } + append_info->colIndex++; +} diff --git a/presto-native-execution/presto_cpp/main/connectors/tpcds/utils/append_info-c.h b/presto-native-execution/presto_cpp/main/connectors/tpcds/utils/append_info-c.h new file mode 100644 index 0000000000000..a02e292c6a859 --- /dev/null +++ b/presto-native-execution/presto_cpp/main/connectors/tpcds/utils/append_info-c.h @@ -0,0 +1,38 @@ +/* + * Licensed 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. + */ + +#pragma once + +#include +#include "presto_cpp/external/dsdgen/include/dsdgen-c/dist.h" + +namespace facebook::velox { +class BaseVector; +using VectorPtr = std::shared_ptr; +} // namespace facebook::velox + +namespace facebook::presto::connector::tpcds { + +struct TpcdsTableDef { + const char* name; + int fl_small; + int fl_child; + int first_column; + int colIndex = 0; + int rowIndex = 0; + DSDGenContext* dsdGenContext; + std::vector children; + bool IsNull(int32_t column); +}; +} // namespace facebook::presto::connector::tpcds diff --git a/presto-native-execution/presto_cpp/main/tests/CMakeLists.txt b/presto-native-execution/presto_cpp/main/tests/CMakeLists.txt index 3af79b15668d6..f4a3f8f932a58 100644 --- a/presto-native-execution/presto_cpp/main/tests/CMakeLists.txt +++ b/presto-native-execution/presto_cpp/main/tests/CMakeLists.txt @@ -53,6 +53,10 @@ target_link_libraries( GTest::gtest GTest::gtest_main) +if(PRESTO_ENABLE_TPCDS_CONNECTOR) + target_link_libraries(presto_server_test presto_tpcds_connector) +endif() + set_property(TARGET presto_server_test PROPERTY JOB_POOL_LINK presto_link_job_pool) diff --git a/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/TpcdsConnectorProtocol.h b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/TpcdsConnectorProtocol.h new file mode 100644 index 0000000000000..15711cd59d551 --- /dev/null +++ b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/TpcdsConnectorProtocol.h @@ -0,0 +1,33 @@ +/* + * Licensed 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. + */ + +#pragma once + +#include "presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.h" +#include "presto_cpp/presto_protocol/core/ConnectorProtocol.h" + +namespace facebook::presto::protocol::tpcds { + +using TpcdsConnectorProtocol = ConnectorProtocolTemplate< + TpcdsTableHandle, + TpcdsTableLayoutHandle, + TpcdsColumnHandle, + NotImplemented, + NotImplemented, + TpcdsSplit, + TpcdsPartitioningHandle, + TpcdsTransactionHandle, + NotImplemented>; + +} // namespace facebook::presto::protocol::tpcds diff --git a/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol-json-cpp.mustache b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol-json-cpp.mustache new file mode 100644 index 0000000000000..b5aa3d9e5386d --- /dev/null +++ b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol-json-cpp.mustache @@ -0,0 +1,146 @@ +/* + * Licensed 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. + */ +// presto_protocol.prolog.cpp +// + +{{#.}} +{{#comment}} +{{comment}} +{{/comment}} +{{/.}} + + +#include "presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.h" +using namespace std::string_literals; + +namespace facebook::presto::protocol::tpcds { + +void to_json(json& j, const TpcdsTransactionHandle& p) { + j = json::array(); + j.push_back(p._type); + j.push_back(p.instance); +} + +void from_json(const json& j, TpcdsTransactionHandle& p) { + j[0].get_to(p._type); + j[1].get_to(p.instance); +} +} // namespace facebook::presto::protocol +{{#.}} +{{#cinc}} +{{&cinc}} +{{/cinc}} +{{^cinc}} +{{#struct}} +namespace facebook::presto::protocol::tpcds { + {{#super_class}} + {{&class_name}}::{{&class_name}}() noexcept { + _type = "{{json_key}}"; + } + {{/super_class}} + + void to_json(json& j, const {{&class_name}}& p) { + j = json::object(); + {{#super_class}} + j["@type"] = "{{&json_key}}"; + {{/super_class}} + {{#fields}} + to_json_key(j, "{{&field_name}}", p.{{field_name}}, "{{&class_name}}", "{{&field_text}}", "{{&field_name}}"); + {{/fields}} + } + + void from_json(const json& j, {{&class_name}}& p) { + {{#super_class}} + p._type = j["@type"]; + {{/super_class}} + {{#fields}} + from_json_key(j, "{{&field_name}}", p.{{field_name}}, "{{&class_name}}", "{{&field_text}}", "{{&field_name}}"); + {{/fields}} + } +} +{{/struct}} +{{#enum}} +namespace facebook::presto::protocol::tpcds { + //Loosly copied this here from NLOHMANN_JSON_SERIALIZE_ENUM() + + // NOLINTNEXTLINE: cppcoreguidelines-avoid-c-arrays + static const std::pair<{{&class_name}}, json> + {{&class_name}}_enum_table[] = { // NOLINT: cert-err58-cpp + {{#elements}} + { {{&class_name}}::{{&element}}, "{{&element}}" }{{^_last}},{{/_last}} + {{/elements}} + }; + void to_json(json& j, const {{&class_name}}& e) + { + static_assert(std::is_enum<{{&class_name}}>::value, "{{&class_name}} must be an enum!"); + const auto* it = std::find_if(std::begin({{&class_name}}_enum_table), std::end({{&class_name}}_enum_table), + [e](const std::pair<{{&class_name}}, json>& ej_pair) -> bool + { + return ej_pair.first == e; + }); + j = ((it != std::end({{&class_name}}_enum_table)) ? it : std::begin({{&class_name}}_enum_table))->second; + } + void from_json(const json& j, {{&class_name}}& e) + { + static_assert(std::is_enum<{{&class_name}}>::value, "{{&class_name}} must be an enum!"); + const auto* it = std::find_if(std::begin({{&class_name}}_enum_table), std::end({{&class_name}}_enum_table), + [&j](const std::pair<{{&class_name}}, json>& ej_pair) -> bool + { + return ej_pair.second == j; + }); + e = ((it != std::end({{&class_name}}_enum_table)) ? it : std::begin({{&class_name}}_enum_table))->first; + } +} +{{/enum}} +{{#abstract}} +namespace facebook::presto::protocol::tpcds { + void to_json(json& j, const std::shared_ptr<{{&class_name}}>& p) { + if ( p == nullptr ) { + return; + } + String type = p->_type; + + {{#subclasses}} + if ( type == "{{&key}}" ) { + j = *std::static_pointer_cast<{{&type}}>(p); + return; + } + {{/subclasses}} + + throw TypeError(type + " no abstract type {{&class_name}} {{&key}}"); + } + + void from_json(const json& j, std::shared_ptr<{{&class_name}}>& p) { + String type; + try { + type = p->getSubclassKey(j); + } catch (json::parse_error &e) { + throw ParseError(std::string(e.what()) + " {{&class_name}} {{&key}} {{&class_name}}"); + } + + {{#subclasses}} + if ( type == "{{&key}}" ) { + std::shared_ptr<{{&type}}> k = std::make_shared<{{&type}}>(); + j.get_to(*k); + p = std::static_pointer_cast<{{&class_name}}>(k); + return; + } + {{/subclasses}} + + throw TypeError(type + " no abstract type {{&class_name}} {{&key}}"); + } +} +{{/abstract}} +{{/cinc}} +{{/.}} diff --git a/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol-json-hpp.mustache b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol-json-hpp.mustache new file mode 100644 index 0000000000000..13b0dc952ac23 --- /dev/null +++ b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol-json-hpp.mustache @@ -0,0 +1,68 @@ +/* + * Licensed 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. + */ +#pragma once + +{{#.}} +{{#comment}} +{{comment}} +{{/comment}} +{{/.}} + +#include +#include + +#include "presto_cpp/external/json/nlohmann/json.hpp" +#include "presto_cpp/presto_protocol/core/presto_protocol_core.h" + +namespace facebook::presto::protocol::tpcds { +struct TpcdsTransactionHandle : public ConnectorTransactionHandle { + String instance = {}; + }; +void to_json(json& j, const TpcdsTransactionHandle& p); + +void from_json(const json& j, TpcdsTransactionHandle& p); +} //namespace facebook::presto::protocol +{{#.}} +{{#hinc}} +{{&hinc}} +{{/hinc}} +{{^hinc}} +{{#struct}} +namespace facebook::presto::protocol::tpcds { + struct {{class_name}} {{#super_class}}: public {{super_class}}{{/super_class}}{ + {{#fields}} + {{#field_local}}{{#optional}}std::shared_ptr<{{/optional}}{{&field_text}}{{#optional}}>{{/optional}} {{&field_name}} = {};{{/field_local}} + {{/fields}} + + {{#super_class}} + {{class_name}}() noexcept; + {{/super_class}} + }; + void to_json(json& j, const {{class_name}}& p); + void from_json(const json& j, {{class_name}}& p); +} +{{/struct}} +{{#enum}} +namespace facebook::presto::protocol::tpcds { + enum class {{class_name}} { + {{#elements}} + {{&element}}{{^_last}},{{/_last}} + {{/elements}} + }; + extern void to_json(json& j, const {{class_name}}& e); + extern void from_json(const json& j, {{class_name}}& e); +} +{{/enum}} +{{/hinc}} +{{/.}} diff --git a/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.cpp b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.cpp new file mode 100644 index 0000000000000..0124bdf70516b --- /dev/null +++ b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.cpp @@ -0,0 +1,241 @@ +// DO NOT EDIT : This file is generated by chevron +/* + * Licensed 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. + */ +// presto_protocol.prolog.cpp +// + +// This file is generated DO NOT EDIT @generated + +#include "presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.h" +using namespace std::string_literals; + +namespace facebook::presto::protocol::tpcds { + +void to_json(json& j, const TpcdsTransactionHandle& p) { + j = json::array(); + j.push_back(p._type); + j.push_back(p.instance); +} + +void from_json(const json& j, TpcdsTransactionHandle& p) { + j[0].get_to(p._type); + j[1].get_to(p.instance); +} +} // namespace facebook::presto::protocol::tpcds +namespace facebook::presto::protocol::tpcds { +TpcdsColumnHandle::TpcdsColumnHandle() noexcept { + _type = "tpcds"; +} + +void to_json(json& j, const TpcdsColumnHandle& p) { + j = json::object(); + j["@type"] = "tpcds"; + to_json_key( + j, + "columnName", + p.columnName, + "TpcdsColumnHandle", + "String", + "columnName"); + to_json_key(j, "type", p.type, "TpcdsColumnHandle", "Type", "type"); +} + +void from_json(const json& j, TpcdsColumnHandle& p) { + p._type = j["@type"]; + from_json_key( + j, + "columnName", + p.columnName, + "TpcdsColumnHandle", + "String", + "columnName"); + from_json_key(j, "type", p.type, "TpcdsColumnHandle", "Type", "type"); +} +} // namespace facebook::presto::protocol::tpcds +namespace facebook::presto::protocol::tpcds { +TpcdsPartitioningHandle::TpcdsPartitioningHandle() noexcept { + _type = "tpcds"; +} + +void to_json(json& j, const TpcdsPartitioningHandle& p) { + j = json::object(); + j["@type"] = "tpcds"; + to_json_key( + j, "table", p.table, "TpcdsPartitioningHandle", "String", "table"); + to_json_key( + j, + "totalRows", + p.totalRows, + "TpcdsPartitioningHandle", + "int64_t", + "totalRows"); +} + +void from_json(const json& j, TpcdsPartitioningHandle& p) { + p._type = j["@type"]; + from_json_key( + j, "table", p.table, "TpcdsPartitioningHandle", "String", "table"); + from_json_key( + j, + "totalRows", + p.totalRows, + "TpcdsPartitioningHandle", + "int64_t", + "totalRows"); +} +} // namespace facebook::presto::protocol::tpcds +namespace facebook::presto::protocol::tpcds { +void to_json(json& j, const std::shared_ptr& p) { + if (p == nullptr) { + return; + } + String type = p->_type; + + if (type == "tpcds") { + j = *std::static_pointer_cast(p); + return; + } + + throw TypeError(type + " no abstract type ColumnHandle "); +} + +void from_json(const json& j, std::shared_ptr& p) { + String type; + try { + type = p->getSubclassKey(j); + } catch (json::parse_error& e) { + throw ParseError(std::string(e.what()) + " ColumnHandle ColumnHandle"); + } + + if (type == "tpcds") { + std::shared_ptr k = + std::make_shared(); + j.get_to(*k); + p = std::static_pointer_cast(k); + return; + } + + throw TypeError(type + " no abstract type ColumnHandle "); +} +} // namespace facebook::presto::protocol::tpcds +namespace facebook::presto::protocol::tpcds { +TpcdsTableHandle::TpcdsTableHandle() noexcept { + _type = "tpcds"; +} + +void to_json(json& j, const TpcdsTableHandle& p) { + j = json::object(); + j["@type"] = "tpcds"; + to_json_key( + j, "tableName", p.tableName, "TpcdsTableHandle", "String", "tableName"); + to_json_key( + j, + "scaleFactor", + p.scaleFactor, + "TpcdsTableHandle", + "double", + "scaleFactor"); +} + +void from_json(const json& j, TpcdsTableHandle& p) { + p._type = j["@type"]; + from_json_key( + j, "tableName", p.tableName, "TpcdsTableHandle", "String", "tableName"); + from_json_key( + j, + "scaleFactor", + p.scaleFactor, + "TpcdsTableHandle", + "double", + "scaleFactor"); +} +} // namespace facebook::presto::protocol::tpcds +namespace facebook::presto::protocol::tpcds { +TpcdsSplit::TpcdsSplit() noexcept { + _type = "tpcds"; +} + +void to_json(json& j, const TpcdsSplit& p) { + j = json::object(); + j["@type"] = "tpcds"; + to_json_key( + j, + "tableHandle", + p.tableHandle, + "TpcdsSplit", + "TpcdsTableHandle", + "tableHandle"); + to_json_key(j, "partNumber", p.partNumber, "TpcdsSplit", "int", "partNumber"); + to_json_key(j, "totalParts", p.totalParts, "TpcdsSplit", "int", "totalParts"); + to_json_key( + j, + "addresses", + p.addresses, + "TpcdsSplit", + "List", + "addresses"); + to_json_key(j, "noSexism", p.noSexism, "TpcdsSplit", "bool", "noSexism"); +} + +void from_json(const json& j, TpcdsSplit& p) { + p._type = j["@type"]; + from_json_key( + j, + "tableHandle", + p.tableHandle, + "TpcdsSplit", + "TpcdsTableHandle", + "tableHandle"); + from_json_key( + j, "partNumber", p.partNumber, "TpcdsSplit", "int", "partNumber"); + from_json_key( + j, "totalParts", p.totalParts, "TpcdsSplit", "int", "totalParts"); + from_json_key( + j, + "addresses", + p.addresses, + "TpcdsSplit", + "List", + "addresses"); + from_json_key(j, "noSexism", p.noSexism, "TpcdsSplit", "bool", "noSexism"); +} +} // namespace facebook::presto::protocol::tpcds +namespace facebook::presto::protocol::tpcds { +TpcdsTableLayoutHandle::TpcdsTableLayoutHandle() noexcept { + _type = "tpcds"; +} + +void to_json(json& j, const TpcdsTableLayoutHandle& p) { + j = json::object(); + j["@type"] = "tpcds"; + to_json_key( + j, + "table", + p.table, + "TpcdsTableLayoutHandle", + "TpcdsTableHandle", + "table"); +} + +void from_json(const json& j, TpcdsTableLayoutHandle& p) { + p._type = j["@type"]; + from_json_key( + j, + "table", + p.table, + "TpcdsTableLayoutHandle", + "TpcdsTableHandle", + "table"); +} +} // namespace facebook::presto::protocol::tpcds diff --git a/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.h b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.h new file mode 100644 index 0000000000000..eb44440d7721a --- /dev/null +++ b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.h @@ -0,0 +1,106 @@ +// DO NOT EDIT : This file is generated by chevron +/* + * Licensed 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. + */ +#pragma once + +// This file is generated DO NOT EDIT @generated + +#include +#include + +#include "presto_cpp/external/json/nlohmann/json.hpp" +#include "presto_cpp/presto_protocol/core/presto_protocol_core.h" + +namespace facebook::presto::protocol::tpcds { +struct TpcdsTransactionHandle : public ConnectorTransactionHandle { + String instance = {}; +}; +void to_json(json& j, const TpcdsTransactionHandle& p); + +void from_json(const json& j, TpcdsTransactionHandle& p); +} // namespace facebook::presto::protocol::tpcds +/* + * Licensed 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. + */ + +// TpcdsColumnHandle is special since it needs an implementation of +// operator<(). + +namespace facebook::presto::protocol::tpcds { +struct TpcdsColumnHandle : public ColumnHandle { + String columnName = {}; + Type type = {}; + + TpcdsColumnHandle() noexcept; + + bool operator<(const ColumnHandle& o) const override { + return columnName < dynamic_cast(o).columnName; + } +}; +void to_json(json& j, const TpcdsColumnHandle& p); +void from_json(const json& j, TpcdsColumnHandle& p); +} // namespace facebook::presto::protocol::tpcds +namespace facebook::presto::protocol::tpcds { +struct TpcdsPartitioningHandle : public ConnectorPartitioningHandle { + String table = {}; + int64_t totalRows = {}; + + TpcdsPartitioningHandle() noexcept; +}; +void to_json(json& j, const TpcdsPartitioningHandle& p); +void from_json(const json& j, TpcdsPartitioningHandle& p); +} // namespace facebook::presto::protocol::tpcds +namespace facebook::presto::protocol::tpcds { +struct TpcdsTableHandle : public ConnectorTableHandle { + String tableName = {}; + double scaleFactor = {}; + + TpcdsTableHandle() noexcept; +}; +void to_json(json& j, const TpcdsTableHandle& p); +void from_json(const json& j, TpcdsTableHandle& p); +} // namespace facebook::presto::protocol::tpcds +namespace facebook::presto::protocol::tpcds { +struct TpcdsSplit : public ConnectorSplit { + TpcdsTableHandle tableHandle = {}; + int partNumber = {}; + int totalParts = {}; + List addresses = {}; + bool noSexism = {}; + + TpcdsSplit() noexcept; +}; +void to_json(json& j, const TpcdsSplit& p); +void from_json(const json& j, TpcdsSplit& p); +} // namespace facebook::presto::protocol::tpcds +namespace facebook::presto::protocol::tpcds { +struct TpcdsTableLayoutHandle : public ConnectorTableLayoutHandle { + TpcdsTableHandle table = {}; + TupleDomain> predicate = {}; + + TpcdsTableLayoutHandle() noexcept; +}; +void to_json(json& j, const TpcdsTableLayoutHandle& p); +void from_json(const json& j, TpcdsTableLayoutHandle& p); +} // namespace facebook::presto::protocol::tpcds diff --git a/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.yml b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.yml new file mode 100644 index 0000000000000..e874c73bc76ab --- /dev/null +++ b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.yml @@ -0,0 +1,49 @@ +# Licensed 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. + +AbstractClasses: + ColumnHandle: + super: JsonEncodedSubclass + comparable: true + subclasses: + - { name: TpcdsColumnHandle, key: tpcds } + + ConnectorPartitioningHandle: + super: JsonEncodedSubclass + subclasses: + - { name: TpcdsPartitioningHandle, key: tpcds} + + ConnectorTableHandle: + super: JsonEncodedSubclass + subclasses: + - { name: TpcdsTableHandle, key: tpcds } + + ConnectorTableLayoutHandle: + super: JsonEncodedSubclass + subclasses: + - { name: TpcdsTableLayoutHandle, key: tpcds } + + ConnectorSplit: + super: JsonEncodedSubclass + subclasses: + - { name: TpcdsSplit, key: tpcds } + +UpdateFields: + TpcdsTableLayoutHandle: + std::shared_ptr: remainingPredicate + +JavaClasses: + - presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsSplit.java + - presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsTableHandle.java + - presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsTableLayoutHandle.java + - presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsColumnHandle.java + - presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsPartitioningHandle.java diff --git a/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/special/TpcdsColumnHandle.hpp.inc b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/special/TpcdsColumnHandle.hpp.inc new file mode 100644 index 0000000000000..c0f21bcf6873a --- /dev/null +++ b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/special/TpcdsColumnHandle.hpp.inc @@ -0,0 +1,31 @@ +/* + * Licensed 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. + */ + +// TpcdsColumnHandle is special since it needs an implementation of +// operator<(). + +namespace facebook::presto::protocol::tpcds { +struct TpcdsColumnHandle : public ColumnHandle { + String columnName = {}; + Type type = {}; + + TpcdsColumnHandle() noexcept; + + bool operator<(const ColumnHandle& o) const override { + return columnName < dynamic_cast(o).columnName; + } +}; +void to_json(json& j, const TpcdsColumnHandle& p); +void from_json(const json& j, TpcdsColumnHandle& p); +} // namespace facebook::presto::protocol::tpcds diff --git a/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/special/TpcdsTransactionHandle.cpp.inc b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/special/TpcdsTransactionHandle.cpp.inc new file mode 100644 index 0000000000000..f741669d72dc7 --- /dev/null +++ b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/special/TpcdsTransactionHandle.cpp.inc @@ -0,0 +1,30 @@ +/* + * Licensed 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. + */ + +// TpcdsTransactionHandle is special since +// the corresponding class in Java is an enum. + +namespace facebook::presto::protocol { + +void to_json(json& j, const TpcdsTransactionHandle& p) { + j = json::array(); + j.push_back(p._type); + j.push_back(p.instance); +} + +void from_json(const json& j, TpcdsTransactionHandle& p) { + j[0].get_to(p._type); + j[1].get_to(p.instance); +} +} // namespace facebook::presto::protocol diff --git a/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/special/TpcdsTransactionHandle.hpp.inc b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/special/TpcdsTransactionHandle.hpp.inc new file mode 100644 index 0000000000000..d665925648813 --- /dev/null +++ b/presto-native-execution/presto_cpp/presto_protocol/connector/tpcds/special/TpcdsTransactionHandle.hpp.inc @@ -0,0 +1,28 @@ +/* + * Licensed 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. + */ + +// TpcdsTransactionHandle is special since +// the corresponding class in Java is an enum. + +namespace facebook::presto::protocol { + +struct TpcdsTransactionHandle : public ConnectorTransactionHandle { + String instance = {}; +}; + +void to_json(json& j, const TpcdsTransactionHandle& p); + +void from_json(const json& j, TpcdsTransactionHandle& p); + +} // namespace facebook::presto::protocol diff --git a/presto-native-execution/presto_cpp/presto_protocol/core/special/ConnectorTransactionHandle.cpp.inc b/presto-native-execution/presto_cpp/presto_protocol/core/special/ConnectorTransactionHandle.cpp.inc index 8ec2a94e84bd9..1b89a65615b1a 100644 --- a/presto-native-execution/presto_cpp/presto_protocol/core/special/ConnectorTransactionHandle.cpp.inc +++ b/presto-native-execution/presto_cpp/presto_protocol/core/special/ConnectorTransactionHandle.cpp.inc @@ -13,6 +13,7 @@ */ // dependency TpchTransactionHandle +// dependency TpcdsTransactionHandle namespace facebook::presto::protocol { void to_json(json& j, const std::shared_ptr& p) { diff --git a/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.cpp b/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.cpp index c15084817a434..107ef068fae41 100644 --- a/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.cpp +++ b/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.cpp @@ -17,5 +17,6 @@ #include "presto_cpp/presto_protocol/connector/hive/presto_protocol_hive.cpp" #include "presto_cpp/presto_protocol/connector/iceberg/presto_protocol_iceberg.cpp" +#include "presto_cpp/presto_protocol/connector/tpcds/presto_protocol_tpcds.cpp" #include "presto_cpp/presto_protocol/connector/tpch/presto_protocol_tpch.cpp" #include "presto_cpp/presto_protocol/core/presto_protocol_core.cpp" diff --git a/presto-native-execution/scripts/setup-centos.sh b/presto-native-execution/scripts/setup-centos.sh index 5d237460bb404..73777c6e0c9f2 100755 --- a/presto-native-execution/scripts/setup-centos.sh +++ b/presto-native-execution/scripts/setup-centos.sh @@ -31,6 +31,7 @@ function install_presto_deps_from_package_managers { dnf install -y maven java clang-tools-extra jq perl-XML-XPath # This python version is installed by the Velox setup scripts pip install regex pyyaml chevron black + dnf install -y vim-common } function install_gperf { diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestNativeTpcdsConnectorQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestNativeTpcdsConnectorQueries.java new file mode 100644 index 0000000000000..f0b4d554fd5e4 --- /dev/null +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestNativeTpcdsConnectorQueries.java @@ -0,0 +1,83 @@ +/* + * Licensed 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. + */ +package com.facebook.presto.nativeworker; + +import com.facebook.presto.Session; +import com.facebook.presto.tests.AbstractTestQueryFramework; +import org.testng.annotations.Test; + +public abstract class AbstractTestNativeTpcdsConnectorQueries + extends AbstractTestQueryFramework +{ + @Override + public Session getSession() + { + return Session.builder(super.getSession()).setCatalog("tpcds").setSchema("tiny").build(); + } + + @Test + public void testTpcdsTinyTables() + { + Session session = getSession(); + assertQuery(session, "SELECT * FROM catalog_returns"); + assertQuery(session, "SELECT * FROM catalog_sales"); + assertQuery(session, "SELECT * FROM store_sales"); + assertQuery(session, "SELECT * FROM store_returns"); + assertQuery(session, "SELECT * FROM web_sales"); + assertQuery(session, "SELECT * FROM web_returns"); + assertQuery(session, "SELECT * FROM inventory"); + assertQuery(session, "SELECT * FROM item"); + assertQuery(session, "SELECT * FROM customer_address"); + assertQuery(session, "SELECT * FROM customer_demographics"); +// assertQuery(session, "SELECT * FROM call_center"); // failing because of null values, will check + assertQuery(session, "SELECT * FROM customer"); + assertQuery(session, "SELECT * FROM web_site"); + assertQuery(session, "SELECT * FROM web_page"); + assertQuery(session, "SELECT * FROM promotion"); + assertQuery(session, "SELECT * FROM reason"); + assertQuery(session, "SELECT * FROM store"); + assertQuery(session, "SELECT * FROM income_band"); + assertQuery(session, "SELECT * FROM household_demographics"); + assertQuery(session, "SELECT * FROM warehouse"); + assertQuery(session, "SELECT * FROM catalog_page"); + assertQuery(session, "SELECT * FROM date_dim"); + assertQuery(session, "SELECT * FROM time_dim"); + assertQuery(session, "SELECT * FROM ship_mode"); + } + + @Test + public void testTpcdsBasicQueries() + { + Session session = getSession(); + assertQuery(session, "SELECT cc_call_center_sk, cc_name, cc_manager, cc_mkt_id, cc_mkt_class FROM call_center"); + assertQuery(session, "SELECT ss_store_sk, SUM(ss_net_paid) AS total_sales " + + "FROM store_sales GROUP BY ss_store_sk ORDER BY total_sales DESC LIMIT 10"); + assertQuery(session, "SELECT sr_item_sk, SUM(sr_return_quantity) AS total_returns " + + "FROM store_returns WHERE sr_item_sk = 12345 GROUP BY sr_item_sk"); + assertQuery(session, "SELECT ws_order_number, SUM(ws_net_paid) AS total_paid FROM web_sales " + + "WHERE ws_sold_date_sk BETWEEN 2451180 AND 2451545 GROUP BY ws_order_number"); + assertQuery(session, "SELECT inv_item_sk, inv_quantity_on_hand FROM inventory WHERE inv_quantity_on_hand > 1000 " + + "ORDER BY inv_quantity_on_hand DESC"); + assertQuery(session, "SELECT SUM(ss_net_paid) AS total_revenue FROM store_sales, promotion " + + "WHERE p_promo_sk = 100 GROUP BY p_promo_sk"); + assertQuery(session, "SELECT c.c_customer_id FROM customer c " + + "JOIN customer_demographics cd ON c.c_customer_sk = cd.cd_demo_sk WHERE cd_purchase_estimate > 5000"); + assertQuery(session, "SELECT cd_gender, AVG(cd_purchase_estimate) AS avg_purchase_estimate FROM customer_demographics" + + " GROUP BY cd_gender ORDER BY avg_purchase_estimate DESC"); + + // No row passes the filter. + assertQuery(session, + "SELECT s_store_sk, s_store_id, s_number_employees FROM store WHERE s_number_employees > 1000"); + } +} diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/PrestoNativeQueryRunnerUtils.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/PrestoNativeQueryRunnerUtils.java index 58431a64f7ca7..e61ecaa5f1b03 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/PrestoNativeQueryRunnerUtils.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/PrestoNativeQueryRunnerUtils.java @@ -86,6 +86,7 @@ public class PrestoNativeQueryRunnerUtils ParquetHiveSerDe.class.getName(), SymlinkTextInputFormat.class.getName(), HiveIgnoreKeyTextOutputFormat.class.getName()); + private PrestoNativeQueryRunnerUtils() {} public static QueryRunner createQueryRunner(boolean addStorageFormatToPath, boolean isCoordinatorSidecarEnabled) @@ -121,7 +122,7 @@ public static QueryRunner createQueryRunner( defaultQueryRunner.close(); - return createNativeQueryRunner(dataDirectory.get().toString(), prestoServerPath.get(), workerCount, cacheMaxSize, true, Optional.empty(), storageFormat, addStorageFormatToPath, false, isCoordinatorSidecarEnabled, false); + return createNativeQueryRunner(dataDirectory.get().toString(), prestoServerPath.get(), workerCount, cacheMaxSize, true, Optional.empty(), storageFormat, addStorageFormatToPath, false, isCoordinatorSidecarEnabled, false, false); } public static QueryRunner createJavaQueryRunner() @@ -310,7 +311,7 @@ public static QueryRunner createNativeIcebergQueryRunner( false, false, OptionalInt.of(workerCount.orElse(4)), - getExternalWorkerLauncher("iceberg", prestoServerPath, cacheMaxSize, remoteFunctionServerUds, false, false), + getExternalWorkerLauncher("iceberg", prestoServerPath, cacheMaxSize, remoteFunctionServerUds, false, false, false), dataDirectory, addStorageFormatToPath); } @@ -326,7 +327,8 @@ public static QueryRunner createNativeQueryRunner( boolean addStorageFormatToPath, Boolean failOnNestedLoopJoin, boolean isCoordinatorSidecarEnabled, - boolean singleNodeExecutionEnabled) + boolean singleNodeExecutionEnabled, + boolean enableTpcdsConnector) throws Exception { // The property "hive.allow-drop-table" needs to be set to true because security is always "legacy" in NativeQueryRunner. @@ -356,7 +358,7 @@ public static QueryRunner createNativeQueryRunner( hiveProperties, workerCount, Optional.of(Paths.get(addStorageFormatToPath ? dataDirectory + "/" + storageFormat : dataDirectory)), - getExternalWorkerLauncher("hive", prestoServerPath, cacheMaxSize, remoteFunctionServerUds, failOnNestedLoopJoin, isCoordinatorSidecarEnabled)); + getExternalWorkerLauncher("hive", prestoServerPath, cacheMaxSize, remoteFunctionServerUds, failOnNestedLoopJoin, isCoordinatorSidecarEnabled, enableTpcdsConnector)); } public static QueryRunner createNativeCteQueryRunner(boolean useThrift, String storageFormat) @@ -399,13 +401,13 @@ public static QueryRunner createNativeCteQueryRunner(boolean useThrift, String s hiveProperties, workerCount, Optional.of(Paths.get(addStorageFormatToPath ? dataDirectory + "/" + storageFormat : dataDirectory)), - getExternalWorkerLauncher("hive", prestoServerPath, cacheMaxSize, Optional.empty(), false, false)); + getExternalWorkerLauncher("hive", prestoServerPath, cacheMaxSize, Optional.empty(), false, false, false)); } public static QueryRunner createNativeQueryRunner(String remoteFunctionServerUds) throws Exception { - return createNativeQueryRunner(false, DEFAULT_STORAGE_FORMAT, Optional.ofNullable(remoteFunctionServerUds), false, false, false); + return createNativeQueryRunner(false, DEFAULT_STORAGE_FORMAT, Optional.ofNullable(remoteFunctionServerUds), false, false, false, false); } public static QueryRunner createNativeQueryRunner(boolean useThrift) @@ -417,13 +419,19 @@ public static QueryRunner createNativeQueryRunner(boolean useThrift) public static QueryRunner createNativeQueryRunner(boolean useThrift, boolean failOnNestedLoopJoin) throws Exception { - return createNativeQueryRunner(useThrift, DEFAULT_STORAGE_FORMAT, Optional.empty(), failOnNestedLoopJoin, false, false); + return createNativeQueryRunner(useThrift, DEFAULT_STORAGE_FORMAT, Optional.empty(), failOnNestedLoopJoin, false, false, false); + } + + public static QueryRunner createNativeQueryRunner(boolean useThrift, boolean failOnNestedLoopJoin, boolean enableTpcdsConnector) + throws Exception + { + return createNativeQueryRunner(useThrift, DEFAULT_STORAGE_FORMAT, Optional.empty(), failOnNestedLoopJoin, false, false, enableTpcdsConnector); } public static QueryRunner createNativeQueryRunner(boolean useThrift, String storageFormat) throws Exception { - return createNativeQueryRunner(useThrift, storageFormat, Optional.empty(), false, false, false); + return createNativeQueryRunner(useThrift, storageFormat, Optional.empty(), false, false, false, false); } public static QueryRunner createNativeQueryRunner( @@ -432,7 +440,8 @@ public static QueryRunner createNativeQueryRunner( Optional remoteFunctionServerUds, Boolean failOnNestedLoopJoin, boolean isCoordinatorSidecarEnabled, - boolean singleNodeExecutionEnabled) + boolean singleNodeExecutionEnabled, + boolean enableTpcdsConnector) throws Exception { int cacheMaxSize = 0; @@ -448,7 +457,8 @@ public static QueryRunner createNativeQueryRunner( true, failOnNestedLoopJoin, isCoordinatorSidecarEnabled, - singleNodeExecutionEnabled); + singleNodeExecutionEnabled, + enableTpcdsConnector); } // Start the remote function server. Return the UDS path used to communicate with it. @@ -475,10 +485,10 @@ public static String startRemoteFunctionServer(String remoteFunctionServerBinary public static NativeQueryRunnerParameters getNativeQueryRunnerParameters() { Path prestoServerPath = Paths.get(getProperty("PRESTO_SERVER") - .orElse("_build/debug/presto_cpp/main/presto_server")) + .orElse("_build/debug/presto_cpp/main/presto_server")) .toAbsolutePath(); Path dataDirectory = Paths.get(getProperty("DATA_DIR") - .orElse("target/velox_data")) + .orElse("target/velox_data")) .toAbsolutePath(); Optional workerCount = getProperty("WORKER_COUNT").map(Integer::parseInt); @@ -495,7 +505,8 @@ public static NativeQueryRunnerParameters getNativeQueryRunnerParameters() return new NativeQueryRunnerParameters(prestoServerPath, dataDirectory, workerCount); } - public static Optional> getExternalWorkerLauncher(String catalogName, String prestoServerPath, int cacheMaxSize, Optional remoteFunctionServerUds, Boolean failOnNestedLoopJoin, boolean isCoordinatorSidecarEnabled) + public static Optional> getExternalWorkerLauncher(String catalogName, String prestoServerPath, int cacheMaxSize, Optional remoteFunctionServerUds, Boolean failOnNestedLoopJoin, boolean isCoordinatorSidecarEnabled, + boolean enableTpcdsConnector) { return Optional.of((workerIndex, discoveryUri) -> { @@ -558,6 +569,12 @@ public static Optional> getExternalWorkerLaunc Files.write(catalogDirectoryPath.resolve("tpchstandard.properties"), format("connector.name=tpch%n").getBytes()); + // Add a tpcds catalog. + if (enableTpcdsConnector) { + Files.write(catalogDirectoryPath.resolve("tpcds.properties"), + format("connector.name=tpcds%n").getBytes()); + } + // Disable stack trace capturing as some queries (using TRY) generate a lot of exceptions. return new ProcessBuilder(prestoServerPath, "--logtostderr=1", "--v=1") .directory(tempDirectoryPath.toFile()) diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestPrestoNativeSystemQueriesSingleNode.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestPrestoNativeSystemQueriesSingleNode.java index 10cba774d2ddc..31b9b54f4a80f 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestPrestoNativeSystemQueriesSingleNode.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestPrestoNativeSystemQueriesSingleNode.java @@ -31,7 +31,8 @@ protected QueryRunner createQueryRunner() Optional.empty(), false, false, - true); + true, + false); } @Override diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestPrestoNativeTpcdsConnectorQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestPrestoNativeTpcdsConnectorQueries.java new file mode 100644 index 0000000000000..26b93042df34b --- /dev/null +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestPrestoNativeTpcdsConnectorQueries.java @@ -0,0 +1,35 @@ +/* + * Licensed 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. + */ +package com.facebook.presto.nativeworker; + +import com.facebook.presto.testing.ExpectedQueryRunner; +import com.facebook.presto.testing.QueryRunner; + +public class TestPrestoNativeTpcdsConnectorQueries + extends AbstractTestNativeTpcdsConnectorQueries +{ + @Override + protected QueryRunner createQueryRunner() + throws Exception + { + return PrestoNativeQueryRunnerUtils.createNativeQueryRunner(false, false, true); + } + + @Override + protected ExpectedQueryRunner createExpectedQueryRunner() + throws Exception + { + return PrestoNativeQueryRunnerUtils.createJavaQueryRunner(); + } +} diff --git a/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsConnectorFactory.java b/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsConnectorFactory.java index 814e56e3136d9..4fed5910872af 100644 --- a/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsConnectorFactory.java +++ b/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsConnectorFactory.java @@ -64,6 +64,7 @@ public ConnectorHandleResolver getHandleResolver() public Connector create(String catalogName, Map config, ConnectorContext context) { int splitsPerNode = getSplitsPerNode(config); + boolean useVarcharType = useVarcharType(config); NodeManager nodeManager = context.getNodeManager(); return new Connector() { @@ -76,7 +77,7 @@ public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel @Override public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) { - return new TpcdsMetadata(); + return new TpcdsMetadata(useVarcharType); } @Override @@ -109,6 +110,16 @@ private int getSplitsPerNode(Map properties) } } + private boolean useVarcharType(Map properties) + { + try { + return parseBoolean(firstNonNull(properties.get("tpcds.use-varchar-type"), String.valueOf(false))); + } + catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid property tpcds.use-varchar-type"); + } + } + private boolean isWithNoSexism(Map properties) { return parseBoolean(firstNonNull(properties.get("tpcds.with-no-sexism"), String.valueOf(false))); diff --git a/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsMetadata.java b/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsMetadata.java index d571057317e39..745191d13b4b1 100644 --- a/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsMetadata.java +++ b/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsMetadata.java @@ -64,13 +64,16 @@ public class TpcdsMetadata private final Set tableNames; private final TpcdsTableStatisticsFactory tpcdsTableStatisticsFactory = new TpcdsTableStatisticsFactory(); - public TpcdsMetadata() + private final boolean useVarcharType; + + public TpcdsMetadata(boolean useVarcharType) { ImmutableSet.Builder tableNames = ImmutableSet.builder(); for (Table tpcdsTable : Table.getBaseTables()) { tableNames.add(tpcdsTable.getName().toLowerCase(ENGLISH)); } this.tableNames = tableNames.build(); + this.useVarcharType = useVarcharType; } @Override @@ -134,14 +137,14 @@ public ConnectorTableMetadata getTableMetadata(ConnectorSession session, Connect Table table = Table.getTable(tpcdsTableHandle.getTableName()); String schemaName = scaleFactorSchemaName(tpcdsTableHandle.getScaleFactor()); - return getTableMetadata(schemaName, table); + return getTableMetadata(schemaName, table, useVarcharType); } - private static ConnectorTableMetadata getTableMetadata(String schemaName, Table tpcdsTable) + private static ConnectorTableMetadata getTableMetadata(String schemaName, Table tpcdsTable, boolean useVarcharType) { ImmutableList.Builder columns = ImmutableList.builder(); for (Column column : tpcdsTable.getColumns()) { - columns.add(new ColumnMetadata(column.getName(), getPrestoType(column.getType()))); + columns.add(new ColumnMetadata(column.getName(), getPrestoType(column.getType(), useVarcharType))); } SchemaTableName tableName = new SchemaTableName(schemaName, tpcdsTable.getName()); return new ConnectorTableMetadata(tableName, columns.build()); @@ -189,7 +192,7 @@ public Map> listTableColumns(ConnectorSess for (String schemaName : getSchemaNames(session, Optional.ofNullable(prefix.getSchemaName()))) { for (Table tpcdsTable : Table.getBaseTables()) { if (prefix.getTableName() == null || tpcdsTable.getName().equals(prefix.getTableName())) { - ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpcdsTable); + ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpcdsTable, useVarcharType); tableColumns.put(new SchemaTableName(schemaName, tpcdsTable.getName()), tableMetadata.getColumns()); } } @@ -243,7 +246,7 @@ public static double schemaNameToScaleFactor(String schemaName) } } - public static Type getPrestoType(ColumnType tpcdsType) + public static Type getPrestoType(ColumnType tpcdsType, boolean useVarcharType) { switch (tpcdsType.getBase()) { case IDENTIFIER: @@ -255,6 +258,9 @@ public static Type getPrestoType(ColumnType tpcdsType) case DECIMAL: return createDecimalType(tpcdsType.getPrecision().get(), tpcdsType.getScale().get()); case CHAR: + if (useVarcharType) { + return createVarcharType(tpcdsType.getPrecision().get()); + } return createCharType(tpcdsType.getPrecision().get()); case VARCHAR: return createVarcharType(tpcdsType.getPrecision().get()); diff --git a/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsRecordSet.java b/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsRecordSet.java index a3821d2cdc307..2d6c461fbd54a 100644 --- a/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsRecordSet.java +++ b/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsRecordSet.java @@ -57,7 +57,10 @@ public TpcdsRecordSet(Results results, List columns) this.columns = ImmutableList.copyOf(columns); ImmutableList.Builder columnTypes = ImmutableList.builder(); for (Column column : columns) { - columnTypes.add(getPrestoType(column.getType())); + // The TPCDS config tpcds.use-varchar-type is set to true only for native execution, since char type is + // currently unsupported in Presto native. This function is only used by the Presto java TPCDS connector + // so the argument useVarcharType is false here. + columnTypes.add(getPrestoType(column.getType(), false)); } this.columnTypes = columnTypes.build(); } @@ -103,7 +106,7 @@ public long getReadTimeNanos() @Override public Type getType(int field) { - return getPrestoType(columns.get(field).getType()); + return getPrestoType(columns.get(field).getType(), false); } @Override diff --git a/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsSplitManager.java b/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsSplitManager.java index 77cd902330026..10ae57007cb6a 100644 --- a/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsSplitManager.java +++ b/presto-tpcds/src/main/java/com/facebook/presto/tpcds/TpcdsSplitManager.java @@ -24,10 +24,13 @@ import com.facebook.presto.spi.connector.ConnectorTransactionHandle; import com.google.common.collect.ImmutableList; +import java.util.HashSet; import java.util.Set; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableSet; import static java.util.Objects.requireNonNull; public class TpcdsSplitManager @@ -62,12 +65,24 @@ public ConnectorSplitSource getSplits( int totalParts = nodes.size() * splitsPerNode; int partNumber = 0; - // Split the data using split and skew by the number of nodes available. + // For larger tables, split the data using split and skew by the number of nodes available. + // The TPCDS connector in presto native uses dsdgen-c for data generation. For certain smaller tables, + // the data cannot be generated in parallel. For these cases, a single split should be processed by + // only one of the worker nodes. + Set smallTables = unmodifiableSet(new HashSet<>(asList("call_center", "item", "store", "web_page", "web_site"))); ImmutableList.Builder splits = ImmutableList.builder(); - for (Node node : nodes) { - for (int i = 0; i < splitsPerNode; i++) { - splits.add(new TpcdsSplit(tableHandle, partNumber, totalParts, ImmutableList.of(node.getHostAndPort()), noSexism)); - partNumber++; + if (smallTables.contains(tableHandle.getTableName())) { + Node node = nodes.stream() + .findFirst() + .orElse(null); + splits.add(new TpcdsSplit(tableHandle, 0, 1, ImmutableList.of(node.getHostAndPort()), noSexism)); + } + else { + for (Node node : nodes) { + for (int i = 0; i < splitsPerNode; i++) { + splits.add(new TpcdsSplit(tableHandle, partNumber, totalParts, ImmutableList.of(node.getHostAndPort()), noSexism)); + partNumber++; + } } } return new FixedSplitSource(splits.build()); diff --git a/presto-tpcds/src/test/java/com/facebook/presto/tpcds/TestTpcdsMetadataStatistics.java b/presto-tpcds/src/test/java/com/facebook/presto/tpcds/TestTpcdsMetadataStatistics.java index 5d732fff6e1b8..432ef7c665f43 100644 --- a/presto-tpcds/src/test/java/com/facebook/presto/tpcds/TestTpcdsMetadataStatistics.java +++ b/presto-tpcds/src/test/java/com/facebook/presto/tpcds/TestTpcdsMetadataStatistics.java @@ -45,7 +45,7 @@ public class TestTpcdsMetadataStatistics { private static final EstimateAssertion estimateAssertion = new EstimateAssertion(0.01); private static final ConnectorSession session = null; - private final TpcdsMetadata metadata = new TpcdsMetadata(); + private final TpcdsMetadata metadata = new TpcdsMetadata(false); @Test public void testNoTableStatsForNotSupportedSchema()