@Override public String getBaseTypeName() throws SQLException { return baseType.getSqlTypeName(); }
/** * Convert an input delimited string into a phoenix array of the configured type. * * @param input string containing delimited array values * @return the array containing the values represented in the input string */ public Array toArray(Object input) throws SQLException { if (input == null) { return conn.createArrayOf(elementDataType.getSqlTypeName(), new Object[0]); } List<?> list = (List<?>) input; if (list.isEmpty()) { return conn.createArrayOf(elementDataType.getSqlTypeName(), new Object[0]); } return conn.createArrayOf(elementDataType.getSqlTypeName(), Lists.newArrayList(Iterables.transform(list, elementConvertFunction)).toArray()); } }
/** * Convert an input delimited string into a phoenix array of the configured type. * * @param input string containing delimited array values * @return the array containing the values represented in the input string */ public Array toArray(String input) throws SQLException { if (input == null || input.isEmpty()) { return conn.createArrayOf(elementDataType.getSqlTypeName(), new Object[0]); } return conn.createArrayOf( elementDataType.getSqlTypeName(), Lists.newArrayList( Iterables.transform( splitter.split(input), elementConvertFunction)).toArray()); } }
/** * Returns the mapping pig data type for a given phoenix data type. * * @param phoenixDataType * @return */ public static Byte getPigDataTypeForPhoenixType(final PDataType phoenixDataType) { Preconditions.checkNotNull(phoenixDataType); if(phoenixDataType instanceof PArrayDataType) { return DataType.TUPLE; } final Byte pigDataType = PHOENIX_TO_PIG_TYPE.get(phoenixDataType); if (LOG.isDebugEnabled()) { LOG.debug(String.format(" For PhoenixDataType [%s] , pigDataType is [%s] ", phoenixDataType.getSqlTypeName(), DataType.findTypeName(pigDataType))); } return pigDataType; }
/** * Helper method to create a {@link Array} for a specific {@link PDataType}, and set it on * the provided {@code stmt}. */ private static void setArrayInStatement(PreparedStatement stmt, PDataType<?> type, Object[] obj, int position) throws SQLException { Array sqlArray = stmt.getConnection().createArrayOf( PDataType.arrayBaseType(type).getSqlTypeName(), obj); stmt.setArray(position, sqlArray); }
public static String getMetricColumnsDetails() { StringBuilder buffer=new StringBuilder(); for(MetricType metric:MetricType.values()){ if (metric.logLevel() != LogLevel.OFF) { buffer.append(metric.columnName()); buffer.append(" "); buffer.append(metric.dataType.getSqlTypeName()); buffer.append(","); } } return buffer.toString(); }
public static String getArraySqlTypeName(@Nullable Integer maxLength, @Nullable Integer scale, PDataType arrayType) { String baseTypeSqlName = PDataType.arrayBaseType(arrayType).getSqlTypeName(); return appendMaxLengthAndScale(maxLength, scale, baseTypeSqlName) + " " + ARRAY_TYPE_SUFFIX; // for ex - decimal(10,2) ARRAY }
@Override public String toString() { StringBuilder buf = new StringBuilder(columnDefName.getColumnNode().toString()); buf.append(' '); buf.append(dataType.getSqlTypeName()); if (maxLength != null) { buf.append('('); buf.append(maxLength); if (scale != null) { buf.append(','); buf.append(scale); // has both max length and scale. For ex- decimal(10,2) } buf.append(')'); } if (isArray) { buf.append(' '); buf.append(PDataType.ARRAY_TYPE_SUFFIX); buf.append(' '); } return buf.toString(); }
@Override public String getParameterTypeName(int index) throws SQLException { return getParam(index).getDataType().getSqlTypeName(); }
public static PDataType fromSqlTypeName(String sqlTypeName) { for (PDataType t : PDataTypeFactory.getInstance().getTypes()) { if (t.getSqlTypeName().equalsIgnoreCase(sqlTypeName)) return t; } throw newIllegalDataException("Unsupported sql type: " + sqlTypeName); }
@Override public void toSQL(ColumnResolver resolver, StringBuilder buf) { List<ParseNode> children = getChildren(); buf.append(" CAST("); children.get(0).toSQL(resolver, buf); buf.append(" AS "); boolean isArray = dt.isArrayType(); PDataType type = isArray ? PDataType.arrayBaseType(dt) : dt; buf.append(type.getSqlTypeName()); if (maxLength != null) { buf.append('('); buf.append(maxLength); if (scale != null) { buf.append(','); buf.append(scale); // has both max length and scale. For ex- decimal(10,2) } buf.append(')'); } if (isArray) { buf.append(' '); buf.append(PDataType.ARRAY_TYPE_SUFFIX); } buf.append(")"); } }
@Override public String getColumnTypeName(int column) throws SQLException { PDataType type = rowProjector.getColumnProjector(column-1).getExpression().getDataType(); return type == null ? null : type.getSqlTypeName(); }
public static String getSqlTypeName(PDataType dataType, Integer maxLength, Integer scale) { return dataType.isArrayType() ? getArraySqlTypeName(maxLength, scale, dataType) : appendMaxLengthAndScale(maxLength, scale, dataType.getSqlTypeName()); }
ddlBuilder.append("pk").append(i + 1).append(" ").append(pkType.getSqlTypeName()).append(" NOT NULL, ");
private static void compareExperssions(int i, Expression expression, List<TargetDataExpression> targetTypes) throws SQLException { PDataType type = expression.getDataType(); if (type != null && type.isCoercibleTo(targetTypes.get(i).getType())) { ; } else if (targetTypes.get(i).getType() == null || targetTypes.get(i).getType().isCoercibleTo(type)) { targetTypes.get(i).setType(type); } else { throw new SQLExceptionInfo.Builder(SQLExceptionCode .SELECT_COLUMN_TYPE_IN_UNIONALL_DIFFS).setMessage("Column # " + i + " is " + targetTypes.get(i).getType().getSqlTypeName() + " in 1st query where as it is " + type.getSqlTypeName() + " in 2nd query") .build().buildException(); } Integer len = expression.getMaxLength(); if (len != null && (targetTypes.get(i).getMaxLength() == null || len > targetTypes.get(i).getMaxLength())) { targetTypes.get(i).setMaxLength(len); } Integer scale = expression.getScale(); if (scale != null && (targetTypes.get(i).getScale() == null || scale > targetTypes.get(i).getScale())){ targetTypes.get(i).setScale(scale); } SortOrder sortOrder = expression.getSortOrder(); if (sortOrder != null && (!sortOrder.equals(targetTypes.get(i).getSortOrder()))) targetTypes.get(i).setSortOrder(SortOrder.getDefault()); }
/** * Creates a table with the given properties and returns its name. If the table is multi-tenant, * also creates a tenant view for that table and returns the name of the view instead. * @param baseConn a non-tenant specific connection. Used to create the base tables * @param conn a tenant-specific connection, if necessary. Otherwise ignored. * @param isMultiTenant whether or not this table should be multi-tenant * @param pkType the data type of the primary key columns * @param saltBuckets the number of salt buckets if the table is salted, otherwise 0 * @return the table or view name that should be used to access the created table */ private static String initializeAndGetTable(Connection baseConn, Connection conn, boolean isMultiTenant, PDataType pkType, int saltBuckets) throws SQLException { String tableName = generateUniqueName() + "in_test" + pkType.getSqlTypeName() + saltBuckets + (isMultiTenant ? "_multi" : "_single"); String tableDDL = createTableDDL(tableName, pkType, saltBuckets, isMultiTenant); baseConn.createStatement().execute(tableDDL); // if requested, create a tenant specific view and return the view name instead if(isMultiTenant) { String viewName = tableName + "_view"; String viewDDL = "CREATE VIEW " + viewName + " AS SELECT * FROM " + tableName; conn.createStatement().execute(viewDDL); return viewName; } else { return tableName; } }
String ddl = String.format("CREATE %s TABLE %s (K INTEGER PRIMARY KEY, V1 %s)", immutable ? "IMMUTABLE" : "", tableName, dataType.getSqlTypeName()); try (Connection conn = DriverManager.getConnection(getUrl())) { conn.createStatement().execute(ddl); immutable, dataType.getSqlTypeName(), errors); assertFalse(errorMsg, failed);
private void testCompareCompositeKey(Integer saltBuckets, PDataType dataType, SortOrder sortOrder, String whereClause, List<Integer> expectedResults, String orderBy) throws SQLException { String tableName = "t_" + saltBuckets + "_" + dataType + "_" + sortOrder + "_" + baseTableName; String ddl = "create table if not exists " + tableName + " (k1 bigint not null, k2 " + dataType.getSqlTypeName() + (dataType.isFixedWidth() ? " not null" : "") + ", constraint pk primary key (k1,k2 " + sortOrder + "))" + (saltBuckets == null ? "" : (" SALT_BUCKETS= " + saltBuckets)); Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)); conn.createStatement().execute(ddl); if (!dataType.isFixedWidth()) { conn.createStatement().execute("upsert into " + tableName + " values (0, null)"); } conn.createStatement().execute("upsert into " + tableName + " values (1, 0.99)"); conn.createStatement().execute("upsert into " + tableName + " values (2, 1.01)"); conn.createStatement().execute("upsert into " + tableName + " values (3, 2.0)"); conn.createStatement().execute("upsert into " + tableName + " values (4, 1.001)"); conn.commit(); String query = "select k1 from " + tableName + " where " + (whereClause.length() > 0 ? (whereClause + " AND ") : "") + " k2>1.0 " + (orderBy.length() == 0 ? "" : orderBy); try { ResultSet rs = conn.createStatement().executeQuery(query); for (int k : expectedResults) { assertTrue (tableName, rs.next()); assertEquals(tableName, k,rs.getInt(1)); } assertFalse(tableName, rs.next()); } finally { conn.close(); } }
private void assertColumnNamesAndDefinitionsEqual(PTable table, Map<String, String> expected) { Map<String, String> actual = Maps.newHashMap(); for (PColumn column : table.getColumns()) { actual.put(column.getName().getString().trim(), column.getDataType().getSqlTypeName()); } assertEquals(expected, actual); }
builder.setDataType(column.getDataType().getSqlTypeName());