Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bin/phoenix_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def findClasspath(command_name):
command = "%s%s" %(command_path, ' classpath')
return tryDecode(subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read())

def setPath():
def setPath(): # pylint: disable=too-many-statements,too-many-branches
PHOENIX_CLIENT_EMBEDDED_JAR_PATTERN = "phoenix-client-embedded-hbase-*[!s].jar"
PHOENIX_CLIENT_LITE_JAR_PATTERN = "phoenix-client-lite-hbase-*[!s].jar"
PHOENIX_TRACESERVER_JAR_PATTERN = "phoenix-tracing-webapp-*-runnable.jar"
Expand Down Expand Up @@ -140,7 +140,11 @@ def setPath():
hbase_site_file = os.path.join(hbase_conf_dir, "hbase-site.xml")
try:
global zk_tls_args
root = ET.parse(hbase_site_file).getroot()
# hbase-site.xml is optional; without it there are no ZK TLS properties to apply
if os.path.isfile(hbase_site_file):
root = ET.parse(hbase_site_file).getroot()
else:
root = ET.Element("configuration")
zk_hbase_prefix = "hbase.zookeeper.property."
zkcfg = {
prop.find("name").text[len(zk_hbase_prefix):]: prop.find("value").text
Expand Down
9 changes: 9 additions & 0 deletions phoenix-core-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@
<groupId>org.apache.phoenix.thirdparty</groupId>
<artifactId>phoenix-shaded-commons-cli</artifactId>
</dependency>
<!-- phoenix-shaded-protobuf is the relocated protobuf-java 4.x runtime used by the
PROTOBUF data type's descriptor parsing / evolution validation paths. Coexists with
the unshaded com.google.protobuf 2.5.x that HBase 2.x ships for its coprocessor RPC.
The banned-imports rule in the root pom restricts new code under
org.apache.phoenix.protobuf.** to the relocated package. -->
<dependency>
<groupId>org.apache.phoenix.thirdparty</groupId>
<artifactId>phoenix-shaded-protobuf</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down
109 changes: 108 additions & 1 deletion phoenix-core-client/src/main/antlr3/PhoenixSQL.g
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ package org.apache.phoenix.parse;
public void setParseNodeFactory(ParseNodeFactory factory) {
this.factory = factory;
}

/** Test-only: number of ParseContext frames currently on the stack. */
int getContextStackDepth() {
return contextStack.size();
}

public boolean isCountFunction(String field) {
return CountAggregateFunction.NORMALIZED_NAME.equals(SchemaUtil.normalizeIdentifier(field));
Expand All @@ -299,6 +304,17 @@ package org.apache.phoenix.parse;
e.input = input;
throw e;
}

// PROTOBUF / DESCRIPTOR / BUNDLE are matched as NAME, not tokens, so they stay valid identifiers.
private boolean isKw(Token t, String word) {
return word.equalsIgnoreCase(t.getText());
}

private void matchKw(Token t, String word) throws RecognitionException {
if (!isKw(t, word)) {
throwRecognitionException(t);
}
}

public int getBindCount() {
return anonBindNum;
Expand Down Expand Up @@ -536,9 +552,25 @@ oneStatement returns [BindableStatement ret]
| s=use_schema_node
| s=update_statistics_node
| s=execute_upgrade_node
| s=protobuf_descriptor_node
| s=explain_node) { $ret = s; }
;
finally{ contextStack.pop(); }

// Sub-rule so PROTOBUF DDL alternatives do not push oneStatement past javac's 64KB method limit.
protobuf_descriptor_node returns [BindableStatement ret]
: ( cp=create_protobuf_node { $ret = cp; }
| a=alter_protobuf_descriptor_node { $ret = a; }
| d=drop_protobuf_descriptor_node { $ret = d; }
)
;

// Disambiguates `CREATE PROTOBUF DESCRIPTOR ...` vs `CREATE PROTOBUF BUNDLE ...` by the third token.
create_protobuf_node returns [BindableStatement ret]
: ( {isKw(input.LT(3), "bundle")}?=> b=create_protobuf_bundle_node { $ret = b; }
| c=create_protobuf_descriptor_node { $ret = c; }
)
;

explain_node returns [BindableStatement ret]
@init { ExplainOptsAcc opts = new ExplainOptsAcc(); }
Expand Down Expand Up @@ -781,6 +813,50 @@ drop_schema_node returns [DropSchemaStatement ret]
{ret = factory.dropSchema(s, ex!=null, c!=null); }
;

// No inline .proto text; FROM is a pre-compiled FileDescriptorSet URL.
create_protobuf_descriptor_node returns [CreateProtobufDescriptorStatement ret]
: CREATE p=NAME k=NAME { matchKw(p, "protobuf"); matchKw(k, "descriptor"); } (IF NOT ex=EXISTS)? pn=proto_message_name
FROM url=STRING_LITERAL
{
$ret = factory.createProtobufDescriptor(pn, ex != null, url.getText());
}
;

// IF EXISTS is a silent no-op; IF NOT EXISTS is not valid on ALTER.
alter_protobuf_descriptor_node returns [AlterProtobufDescriptorStatement ret]
: ALTER p=NAME k=NAME { matchKw(p, "protobuf"); matchKw(k, "descriptor"); } (IF ex=EXISTS)? pn=proto_message_name
FROM url=STRING_LITERAL
{
$ret = factory.alterProtobufDescriptor(pn, ex != null, url.getText());
}
;

// In-use check is a PROTO_DESC_LINK prefix scan, never SYSTEM.CATALOG.
drop_protobuf_descriptor_node returns [DropProtobufDescriptorStatement ret]
: DROP p=NAME k=NAME { matchKw(p, "protobuf"); matchKw(k, "descriptor"); } (IF ex=EXISTS)? pn=proto_message_name
{ $ret = factory.dropProtobufDescriptor(pn, ex != null); }
;

// Registers every listed name from one FileDescriptorSet, atomically.
create_protobuf_bundle_node returns [CreateProtobufBundleStatement ret]
: CREATE p=NAME k=NAME { matchKw(p, "protobuf"); matchKw(k, "bundle"); } (IF NOT ex=EXISTS)?
LPAREN nl=proto_message_name_list RPAREN
FROM url=STRING_LITERAL
{
$ret = factory.createProtobufBundle(nl, ex != null, url.getText());
}
;

// Comma-separated list of qualified proto message names. List order matches source-text
// order (used for deterministic error messages); registration semantics are order-
// independent. The list must be non-empty (the LPAREN/RPAREN around it makes the grammar
// require at least one name).
proto_message_name_list returns [java.util.List<String> ret]
@init { $ret = new java.util.ArrayList<String>(); }
: first=proto_message_name { $ret.add($first.ret); }
(COMMA next=proto_message_name { $ret.add($next.ret); })*
;


// Parse a drop index statement
drop_index_node returns [DropIndexStatement ret]
Expand Down Expand Up @@ -887,10 +963,11 @@ indexes returns [List<NamedNode> ret]
;

column_def returns [ColumnDef ret]
: c=column_name dt=identifier (LPAREN l=NUMBER (COMMA s=NUMBER)? RPAREN)? ar=ARRAY? (lsq=LSQUARE (a=NUMBER)? RSQUARE)? (nn=NOT? n=NULL)? (DEFAULT df=expression)? ((pk=PRIMARY KEY (order=ASC|order=DESC)? rr=ROW_TIMESTAMP?)|(ENCODED_QUALIFIER eq=NUMBER))?
: c=column_name dt=identifier (LT pn=proto_message_name GT)? (LPAREN l=NUMBER (COMMA s=NUMBER)? RPAREN)? ar=ARRAY? (lsq=LSQUARE (a=NUMBER)? RSQUARE)? (nn=NOT? n=NULL)? (DEFAULT df=expression)? ((pk=PRIMARY KEY (order=ASC|order=DESC)? rr=ROW_TIMESTAMP?)|(ENCODED_QUALIFIER eq=NUMBER))?
{ $ret = factory.columnDef(
c,
dt,
pn,
ar != null || lsq != null,
a == null ? null : Integer.parseInt( a.getText() ),
nn!=null ? Boolean.FALSE : n!=null ? Boolean.TRUE : null,
Expand All @@ -903,6 +980,36 @@ column_def returns [ColumnDef ret]
rr != null); }
;

// Case-preserving parts so reserved words like Order stay valid in PROTOBUF<...>.
proto_message_name returns [String ret]
@init{StringBuilder buf = new StringBuilder();}
: first=proto_message_name_part {buf.append(first);}
(DOT next=proto_message_name_part {buf.append('.').append(next);})*
{$ret = buf.toString();}
;

proto_message_name_part returns [String ret]
: any=~(EOF) {
// STRING_LITERAL text has quotes stripped; reject literals so PROTOBUF<'x'>
// cannot parse as PROTOBUF<x>. Accept NAME or reserved-word tokens only.
int tt = $any.getType();
if (tt == STRING_LITERAL || tt == NUMBER || tt == DECIMAL || tt == DOUBLE
|| tt == HEX_LITERAL || tt == BIN_LITERAL || tt == BIND_NAME) {
throw new RuntimeException(
"Invalid PROTOBUF message-name part: literals (" + $any.getText()
+ ") are not allowed. Each dot-separated part must be an unquoted "
+ "identifier matching [A-Za-z_][A-Za-z0-9_]*.");
}
String text = $any.getText();
if (text == null || !text.matches("[A-Za-z_][A-Za-z0-9_]*")) {
throw new RuntimeException(
"Invalid PROTOBUF message-name part: '" + text
+ "'. Each dot-separated part must match [A-Za-z_][A-Za-z0-9_]*.");
}
$ret = text;
}
;

dyn_column_defs returns [List<ColumnDef> ret]
@init{ret = new ArrayList<ColumnDef>(); }
: v = dyn_column_def {$ret.add(v);} (COMMA v = dyn_column_def {$ret.add(v);} )*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class MetadataRpcController extends DelegatingHBaseRpcController {
.add(PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_NAME)
.add(PhoenixDatabaseMetaData.SYSTEM_FUNCTION_NAME)
.add(PhoenixDatabaseMetaData.SYSTEM_CHILD_LINK_NAME)
.add(PhoenixDatabaseMetaData.SYSTEM_PROTO_DESCRIPTORS_NAME)
.add(PhoenixDatabaseMetaData.SYSTEM_PROTO_DESC_LINK_NAME)
.add(SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES, true)
.getNameAsString())
.add(SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_STATS_NAME_BYTES, true)
Expand All @@ -52,6 +54,12 @@ class MetadataRpcController extends DelegatingHBaseRpcController {
.getNameAsString())
.add(SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CHILD_LINK_NAME_BYTES, true)
.getNameAsString())
.add(SchemaUtil
.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_PROTO_DESCRIPTORS_NAME_BYTES, true)
.getNameAsString())
.add(SchemaUtil
.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_PROTO_DESC_LINK_NAME_BYTES, true)
.getNameAsString())
.build();

public MetadataRpcController(HBaseRpcController delegate, Configuration conf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class ServerRpcController extends DelegatingHBaseRpcController {
.add(PhoenixDatabaseMetaData.SYSTEM_SEQUENCE_NAME)
.add(PhoenixDatabaseMetaData.SYSTEM_FUNCTION_NAME)
.add(PhoenixDatabaseMetaData.SYSTEM_CHILD_LINK_NAME)
.add(PhoenixDatabaseMetaData.SYSTEM_PROTO_DESCRIPTORS_NAME)
.add(PhoenixDatabaseMetaData.SYSTEM_PROTO_DESC_LINK_NAME)
.add(SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES, true)
.getNameAsString())
.add(SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_STATS_NAME_BYTES, true)
Expand All @@ -52,6 +54,12 @@ class ServerRpcController extends DelegatingHBaseRpcController {
.getNameAsString())
.add(SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CHILD_LINK_NAME_BYTES, true)
.getNameAsString())
.add(SchemaUtil
.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_PROTO_DESCRIPTORS_NAME_BYTES, true)
.getNameAsString())
.add(SchemaUtil
.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_PROTO_DESC_LINK_NAME_BYTES, true)
.getNameAsString())
.build();

ServerRpcController(HBaseRpcController delegate, Configuration conf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.phoenix.parse.PSchema;
import org.apache.phoenix.parse.ParseNode;
import org.apache.phoenix.parse.ParseNodeFactory;
import org.apache.phoenix.parse.ProtoValueParseNode;
import org.apache.phoenix.parse.SelectStatement;
import org.apache.phoenix.parse.SingleTableStatement;
import org.apache.phoenix.parse.TableName;
Expand Down Expand Up @@ -306,18 +307,23 @@ public static ColumnResolver getResolverForCreateIndex(SingleTableStatement stat
}

public static ColumnResolver getResolverForCompiledDerivedTable(PhoenixConnection connection,
TableRef tableRef, RowProjector projector) throws SQLException {
TableRef tableRef, QueryPlan innerPlan) throws SQLException {
RowProjector projector = innerPlan.getProjector();
ColumnResolver innerResolver = innerPlan.getContext().getResolver();
List<PColumn> projectedColumns = new ArrayList<PColumn>();
PTable table = tableRef.getTable();
for (PColumn column : table.getColumns()) {
Expression sourceExpression =
projector.getColumnProjector(column.getPosition()).getExpression();
// Derived-table columns are untyped placeholders; the descriptor binding lives on the source.
PColumn source = ProtoValueParseNode.resolveSourceColumn(innerResolver, sourceExpression);
PColumnImpl projectedColumn = new PColumnImpl(column.getName(), column.getFamilyName(),
sourceExpression.getDataType(), sourceExpression.getMaxLength(),
sourceExpression.getScale(), sourceExpression.isNullable(), column.getPosition(),
sourceExpression.getSortOrder(), column.getArraySize(), column.getViewConstant(),
column.isViewReferenced(), column.getExpressionStr(), column.isRowTimestamp(),
column.isDynamic(), column.getColumnQualifierBytes(), column.getTimestamp());
column.isDynamic(), column.getColumnQualifierBytes(), column.getTimestamp(), false,
source == null ? null : source.getProtoMessageName());
projectedColumns.add(projectedColumn);
}
PTable t = PTableImpl.builderWithColumns(table, projectedColumns).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,11 +1154,11 @@ public PTable createProjectedTable(boolean retainPKColumns, StatementContext con
return TupleProjectionCompiler.createProjectedTable(tableRef, sourceColumns, retainPKColumns);
}

public PTable createProjectedTable(RowProjector rowProjector) throws SQLException {
public PTable createProjectedTable(QueryPlan subqueryPlan) throws SQLException {
assert (isSubselect());
TableRef tableRef =
FromCompiler.getResolverForCompiledDerivedTable(phoenixStatement.getConnection(),
this.tableRef, rowProjector).getTables().get(0);
this.tableRef, subqueryPlan).getTables().get(0);
List<ColumnRef> sourceColumns = new ArrayList<ColumnRef>();
PTable table = tableRef.getTable();
for (PColumn column : table.getColumns()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ protected QueryPlan compileJoinQuery(StatementContext context, JoinTable joinTab
false);
}
QueryPlan plan = compileSubquery(subquery, false);
PTable projectedTable = table.createProjectedTable(plan.getProjector());
PTable projectedTable = table.createProjectedTable(plan);
context.setResolver(FromCompiler.getResolverForProjectedTable(projectedTable,
context.getConnection(), subquery.getUdfParseNodes()));
return new TupleProjectionPlan(plan, new TupleProjector(plan.getProjector()), context, null);
Expand Down Expand Up @@ -436,7 +436,7 @@ protected QueryPlan compileJoinQuery(JoinCompiler.Strategy strategy, StatementCo
} else {
SelectStatement subquery = table.getAsSubquery(orderBy);
QueryPlan plan = compileSubquery(subquery, false);
initialProjectedTable = table.createProjectedTable(plan.getProjector());
initialProjectedTable = table.createProjectedTable(plan);
tableRef = plan.getTableRef();
context.getScan().setFamilyMap(plan.getContext().getScan().getFamilyMap());
query = joinTable.getAsSingleSubquery((SelectStatement) plan.getStatement(), asSubquery);
Expand Down Expand Up @@ -541,7 +541,7 @@ protected QueryPlan compileJoinQuery(JoinCompiler.Strategy strategy, StatementCo
} else {
SelectStatement subquery = rhsTable.getAsSubquery(orderBy);
QueryPlan plan = compileSubquery(subquery, false);
rhsProjTable = rhsTable.createProjectedTable(plan.getProjector());
rhsProjTable = rhsTable.createProjectedTable(plan);
rhsTableRef = plan.getTableRef();
context.getScan().setFamilyMap(plan.getContext().getScan().getFamilyMap());
rhs = rhsJoinTable.getAsSingleSubquery((SelectStatement) plan.getStatement(), asSubquery);
Expand Down Expand Up @@ -771,8 +771,8 @@ protected QueryPlan compileSingleQuery(StatementContext context, SelectStatement

// Replace the original resolver and table with those having compiled type info.
TableRef tableRef = context.getResolver().getTables().get(0);
ColumnResolver resolver = FromCompiler.getResolverForCompiledDerivedTable(
statement.getConnection(), tableRef, innerQueryPlanRowProjector);
ColumnResolver resolver = FromCompiler
.getResolverForCompiledDerivedTable(statement.getConnection(), tableRef, innerPlan);
context.setResolver(resolver);
tableRef = resolver.getTables().get(0);
context.setCurrentTable(tableRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.AliasedNode;
import org.apache.phoenix.parse.OrderByNode;
import org.apache.phoenix.parse.ProtoValueParseNode;
import org.apache.phoenix.parse.SelectStatement;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PColumnImpl;
Expand Down Expand Up @@ -92,11 +93,12 @@ public static TableRef contructSchemaTable(PhoenixStatement statement, List<Quer
ColumnProjector colProj = plan.getProjector().getColumnProjector(i);
String name = selectNodes == null ? colProj.getLabel() : selectNodes.get(i).getAlias();
PName colName = PNameFactory.newName(name);
PColumnImpl projectedColumn = new PColumnImpl(PNameFactory.newName(name), UNION_FAMILY_NAME,
targetTypes.get(i).getType(), targetTypes.get(i).getMaxLength(),
targetTypes.get(i).getScale(), colProj.getExpression().isNullable(), i,
targetTypes.get(i).getSortOrder(), 500, null, false, colProj.getExpression().toString(),
false, false, colName.getBytes(), HConstants.LATEST_TIMESTAMP);
PColumnImpl projectedColumn =
new PColumnImpl(PNameFactory.newName(name), UNION_FAMILY_NAME, targetTypes.get(i).getType(),
targetTypes.get(i).getMaxLength(), targetTypes.get(i).getScale(),
colProj.getExpression().isNullable(), i, targetTypes.get(i).getSortOrder(), 500, null,
false, colProj.getExpression().toString(), false, false, colName.getBytes(),
HConstants.LATEST_TIMESTAMP, false, commonProtoMessageName(plans, i));
projectedColumns.add(projectedColumn);
}
Long scn = statement.getConnection().getSCN();
Expand All @@ -118,6 +120,24 @@ public static TableRef contructSchemaTable(PhoenixStatement statement, List<Quer
return new TableRef(null, tempTable, 0, false);
}

/**
* PROTOBUF descriptor name shared by column {@code i} of every branch, or null if any branch
* projects something other than a PROTOBUF column bound to that same descriptor.
*/
private static String commonProtoMessageName(List<QueryPlan> plans, int i) {
String common = null;
for (QueryPlan plan : plans) {
PColumn source = ProtoValueParseNode.resolveSourceColumn(plan.getContext().getResolver(),
plan.getProjector().getColumnProjector(i).getExpression());
String name = source == null ? null : source.getProtoMessageName();
if (name == null || common != null && !common.equals(name)) {
return null;
}
common = name;
}
return common;
}

@SuppressWarnings("rawtypes")
private static void compareExperssions(int i, Expression expression,
List<TargetDataExpression> targetTypes) throws SQLException {
Expand Down
Loading
Loading