[ 
https://issues.apache.org/jira/browse/HAWQ-465?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15206996#comment-15206996
 ] 

ASF GitHub Bot commented on HAWQ-465:
-------------------------------------

Github user hornn commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/479#discussion_r57044521
  
    --- Diff: src/backend/utils/adt/pxf_functions.c ---
    @@ -0,0 +1,164 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +#include "catalog/external/externalmd.h"
    +#include "postgres.h"
    +#include "fmgr.h"
    +#include "funcapi.h"
    +#include "utils/builtins.h"
    +
    +
    +typedef struct ObjectContext
    +{
    +   ListCell *current_object;
    +   ListCell *current_field;
    +} ObjectContext;
    +
    +ListCell* pxf_object_fields_enum_start(text *profile, text *pattern);
    +ObjectContext* pxf_object_fields_enum_next(ObjectContext *object_context);
    +void pxf_object_fields_enum_end(void);
    +
    +ListCell*
    +pxf_object_fields_enum_start(text *profile, text *pattern)
    +{
    +   List *objects = NIL;
    +
    +   char *profile_cstr = text_to_cstring(profile);
    +   char *pattern_cstr = text_to_cstring(pattern);
    +
    +   objects = get_pxf_object_metadata(profile_cstr, pattern_cstr, NULL);
    +
    +   return list_head(objects);
    +}
    +
    +ObjectContext*
    +pxf_object_fields_enum_next(ObjectContext *object_context)
    +{
    +
    +   //first time call
    +   if (object_context->current_object && !object_context->current_field)
    +           object_context->current_field = list_head(((PxfItem *) 
lfirst(object_context->current_object))->fields);
    +
    +   //next field for the same object
    +   else if lnext(object_context->current_field)
    +                   object_context->current_field = 
lnext(object_context->current_field);
    +   //next table
    +   else if lnext(object_context->current_object)
    +   {
    +           object_context->current_object = 
lnext(object_context->current_object);
    +           object_context->current_field = list_head(((PxfItem *) 
lfirst(object_context->current_object))->fields);
    +
    +   //no objects, no fields left
    +   } else
    +           object_context = NULL;
    +
    +   return object_context;
    +}
    +
    +void pxf_object_fields_enum_end(void)
    +{
    +   //cleanup
    +}
    +
    +Datum pxf_get_object_fields(PG_FUNCTION_ARGS)
    +{
    +   MemoryContext oldcontext;
    +   FuncCallContext *funcctx;
    +   HeapTuple tuple;
    +   Datum result;
    +   Datum values[4];
    +   bool nulls[4];
    +
    +   ObjectContext *object_context;
    +
    +   text *profile = PG_GETARG_TEXT_P(0);
    +   text *pattern = PG_GETARG_TEXT_P(1);
    +
    +   /* stuff done only on the first call of the function */
    +   if (SRF_IS_FIRSTCALL())
    +   {
    +           TupleDesc tupdesc;
    +
    +           /* create a function context for cross-call persistence */
    +           funcctx = SRF_FIRSTCALL_INIT();
    +
    +           /*
    +            * switch to memory context appropriate for multiple function 
calls
    +            */
    +           oldcontext = 
MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
    +
    +           /* initialize object fileds metadata scanning code */
    +           object_context = (ObjectContext *) 
palloc0(sizeof(ObjectContext));
    +           object_context->current_object = 
pxf_object_fields_enum_start(profile, pattern);
    +           funcctx->user_fctx = (void *) object_context;
    +
    +           /*
    +            * build tupdesc for result tuples. This must match this 
function's
    +            * pg_proc entry!
    +            */
    +           tupdesc = CreateTemplateTupleDesc(4, false);
    +           TupleDescInitEntry(tupdesc, (AttrNumber) 1, "path",
    +           TEXTOID, -1, 0);
    +           TupleDescInitEntry(tupdesc, (AttrNumber) 2, "objectname",
    +           TEXTOID, -1, 0);
    +           TupleDescInitEntry(tupdesc, (AttrNumber) 3, "columnname",
    +           TEXTOID, -1, 0);
    +           TupleDescInitEntry(tupdesc, (AttrNumber) 4, "columntype",
    --- End diff --
    
    what about the modifiers? are they included in the type?


> Implement stored procedure to return fields metainfo from PXF
> -------------------------------------------------------------
>
>                 Key: HAWQ-465
>                 URL: https://issues.apache.org/jira/browse/HAWQ-465
>             Project: Apache HAWQ
>          Issue Type: Sub-task
>          Components: Hcatalog, PXF
>            Reporter: Oleksandr Diachenko
>            Assignee: Oleksandr Diachenko
>             Fix For: 2.0.0
>
>
> User should be able to call built-in function:
> {code}
> select pxf_get_object_fields('source_name', 'container_name', 'object_name');
>  pxf_get_object_fields 
> {code}
> to retrieve all metadata for given source, container, object.
> Input parameters:
> ||Name||Type||Mode||
> |profile|text|IN|
> |pattern|text|IN|
> |path|text|OUT|
> |objectname|text|OUT|
> |fieldname|text|OUT|
> |fieldtype|text|OUT|
> |fieldmodifiers|text|OUT|
> Example:
> {noformat}
> # select * from pxf_get_object_fields('Hive', 'default/tab*');
>   path  | objectname  | fieldname       |    fieldtype   |  fieldmodifiers |
> ---------+-----------------+------------------ 
> +----------------+-------------------+
> default |      table1     |        col1         |        int4       |     not 
> null       |
> default |      table1     |        col2         |        text       |         
>                |
> default |      table2     |        col1         |        int4       |     not 
> null       |
> default |      table2     |        col2         |        text       |         
>                |
> (4 rows)
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to