hawq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hornn <...@git.apache.org>
Subject [GitHub] incubator-hawq pull request: HAWQ-465. Implement stored procedure ...
Date Wed, 23 Mar 2016 02:27:47 GMT
Github user hornn commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/479#discussion_r57101750
  
    --- 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 --
    
    so what happens now for fields with modifiers such as varchar? IIRC the returned field
is represented in json as {name, type, modifiers}. So are we going to ignore the modifiers
part for now?
    If so maybe add a TODO here. Also it may be better to have a columnmodifiers field even
if we leave it empty, just to avoid later changes in schema/catalog


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message