hawq-dev mailing list archives

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

    https://github.com/apache/incubator-hawq/pull/479#discussion_r57227829
  
    --- 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 --
    
    As for now we do have field for modifiers on Hawq side, but current metadata rest api
doesn't expose those modifiers on PXF side. Also Hive 1.2.1 doesn't support NOT NULL modifiers
for fields, so we decided to not expose modifiers for now and add it later.


---
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