Github user jiny2 commented on a diff in the pull request: https://github.com/apache/incubator-hawq/pull/1314#discussion_r154278719 --- Diff: src/include/access/plugstorage.h --- @@ -0,0 +1,221 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*------------------------------------------------------------------------- + * + * plugstorage.h + * + * Pluggable storage definitions. Support external table for now. + * + *------------------------------------------------------------------------- + */ + +#ifndef PLUGSTORAGE_H +#define PLUGSTORAGE_H + +#include "postgres.h" +#include "postgres_ext.h" +#include "fmgr.h" +#include "nodes/pg_list.h" +#include "nodes/plannodes.h" +#include "nodes/execnodes.h" +#include "access/sdir.h" +#include "access/relscan.h" +#include "access/extprotocol.h" +#include "access/tupdesc.h" +#include "access/fileam.h" +#include "utils/relcache.h" +#include "executor/tuptable.h" + +/* From src/include/access/fileam.h */ +extern char *getExtTblCategoryInFmtOptsStr(char *fmtStr); +extern char *getExtTblFormatterTypeInFmtOptsStr(char *fmtStr); +extern char *getExtTblFormatterTypeInFmtOptsList(List *fmtOpts); + + +/* + * ExternalTableType + * + * enum for different types of external tables. + * + * The different types of external tables can be combinations of different + * protocols and formats. To be specific: + * {GPFDIST, GPFDISTS, HTTP, COMMAND, HDFS} X {TEXT, CSV, ORC} + * + * NOTE: + * + * The GENERIC external table type is used to simplify the call back + * implementation for different combination of external table formats + * and protocols. It need to be improved so that each external table + * type should get its access method with minimum cost during runtime. + * + * The fact is that for custom protocol (HDFS), the format types for + * TEXT, CSV, and ORC external tables are all 'b' in pg_exttable catalog + * table. The formatter information is stored in format options which is + * a list strings. Thus, during read and write access of these tables, + * there will be performance issue if we get the format type and access + * method for them for each tuple. + * + */ +typedef enum +{ + ExternalTableType_GENERIC, /* GENERIC external table format and protocol */ + ExternalTableType_PLUG, /* Pluggable format with hdfs protocol, i.e., ORC */ + ExternalTableType_Invalid +} ExternalTableType; + +/* + * PlugStorageValidatorData is the node type that is passed as fmgr "context" + * info when a function is called by the Pluggable Storage Framework. + */ +typedef struct PlugStorageValidatorData +{ + /* see T_PlugStorageValidatorData */ + NodeTag type; + + /* check if format interfaces are implemented in pg_proc */ + char *format_name; + + /* check if format options and their values are valid */ + List *format_opts; + char *format_str; + char *encoding_name; + bool is_writable; + + /* check if format data types are supported in table definition */ + TupleDesc tuple_desc; + +} PlugStorageValidatorData; + +typedef struct PlugStorageValidatorData *PlugStorageValidator; + +/* + * PlugStorageData is used to pass args between hawq and pluggable data formats. + */ +typedef struct PlugStorageData +{ + NodeTag type; /* see T_PlugStorageData */ + int ps_table_type; + int ps_formatter_type; + char *ps_formatter_name; + int ps_error_ao_seg_no; + Relation ps_relation; + PlanState *ps_plan_state; + ExternalScan *ps_ext_scan; + ScanState *ps_scan_state; + ScanDirection ps_scan_direction; + FileScanDesc ps_file_scan_desc; + ExternalScanState *ps_ext_scan_state; + ResultRelSegFileInfo *ps_result_seg_file_info; + ExternalInsertDesc ps_ext_insert_desc; + ExternalSelectDesc ps_ext_select_desc; + bool ps_has_tuple; + Oid ps_tuple_oid; + TupleTableSlot *ps_tuple_table_slot; + +} PlugStorageData; + +typedef PlugStorageData *PlugStorage; + + +/* + * getExternalTableTypeList + * getExternalTableTypeStr + * + * Return the table type for a given external table + * + * Currently it is an implementation with performance cost due to the + * fact that the format types for TEXT, CSV, and ORC external tables + * with customer protocol (HDFS) are all 'b' in pg_exttable catalog + * table. It needs to visit the format options to get the table type. + */ +void getExternalTableTypeList(const char formatType, + List *formatOptions, + int *formatterType, + char **formatterName); + +void getExternalTableTypeStr(const char formatType, + char *formatOptions, + int *formatterType, --- End diff -- please double check this format
---