Related
After successfully upgrading from ver7 to ver8, can only see admin screens with actual site displaying below error:
Server Error in '/' Application.
Conversion failed when converting from a character string to
uniqueidentifier.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Conversion
failed when converting from a character string to uniqueidentifier.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Conversion failed when converting from a
character string to uniqueidentifier.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection, Action`1 wrapCloseInAction) +3189408
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +753
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj, Boolean& dataReady) +5042
System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
+278 System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more) +295
System.Data.SqlClient.SqlDataReader.Read() +42
System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
+157 System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader,
Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn,
Object parentChapterValue) +225
System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable,
IDataReader dataReader, Int32 startRecord, Int32 maxRecords) +479
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior) +277
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior) +178
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +122
CMS.DataEngine.AbstractDataConnection.ExecuteQuery(String queryText,
QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean
requiresTransaction) +251
[Exception: [DataConnection.HandleError]:
Query: SELECT * FROM (
SELECT [PageID], [MenuItemName], [MenuItemTeaserImage], [Synopsis], [PermanentExhibition], [WheelchairAccessible], NULL AS
[HomeID], NULL AS [MenuItemGroup], ClassName, DocumentCulture,
DocumentGUID, DocumentModifiedWhen, DocumentMenuCaption,
DocumentMenuClass, DocumentMenuClassHighLighted,
DocumentMenuClassOver, DocumentShowInSiteMap,
DocumentMenuItemHideInNavigation, DocumentMenuItemImage,
DocumentMenuItemImageHighlighted, DocumentMenuItemImageOver,
DocumentMenuItemInactive, DocumentMenuItemLeftImage,
DocumentMenuItemLeftImageHighlighted, DocumentMenuItemLeftImageOver,
DocumentMenuItemRightImage, DocumentMenuItemRightImageHighlighted,
DocumentMenuItemRightImageOver, DocumentMenuJavascript,
DocumentMenuRedirectUrl, DocumentMenuRedirectToFirstChild,
DocumentMenuStyle, DocumentMenuStyleHighlighted,
DocumentMenuStyleOver, DocumentName, DocumentUrlPath, NodeAliasPath,
NodeID, NodeChildNodesCount, NodeClassID, NodeLevel, NodeLinkedNodeID,
NodeParentID, SiteName, NodeACLID, NodeSiteID, NodeOwner, NodeOrder,
NodeName, DocumentSitemapSettings, NodeOrder AS CMS_O1, ROW_NUMBER()
OVER (ORDER BY DocumentName) AS CMS_SRN, 0 AS CMS_SN,
'cms.document.nmi.page' AS CMS_T FROM View_NMI_Page_Joined WHERE
NodeSiteID = #NodeSiteID AND (DocumentMenuItemHideInNavigation = 0)
AND (Published = #Published AND NodeLevel <= #NodeLevel AND
DocumentCulture = #DocumentCulture) UNION ALL SELECT NULL AS
[PageID], [MenuItemName], [MenuItemTeaserImage], NULL AS [Synopsis],
NULL AS [PermanentExhibition], NULL AS [WheelchairAccessible],
[HomeID], [MenuItemGroup], ClassName, DocumentCulture, DocumentGUID,
DocumentModifiedWhen, DocumentMenuCaption, DocumentMenuClass,
DocumentMenuClassHighLighted, DocumentMenuClassOver,
DocumentShowInSiteMap, DocumentMenuItemHideInNavigation,
DocumentMenuItemImage, DocumentMenuItemImageHighlighted,
DocumentMenuItemImageOver, DocumentMenuItemInactive,
DocumentMenuItemLeftImage, DocumentMenuItemLeftImageHighlighted,
DocumentMenuItemLeftImageOver, DocumentMenuItemRightImage,
DocumentMenuItemRightImageHighlighted, DocumentMenuItemRightImageOver,
DocumentMenuJavascript, DocumentMenuRedirectUrl,
DocumentMenuRedirectToFirstChild, DocumentMenuStyle,
DocumentMenuStyleHighlighted, DocumentMenuStyleOver, DocumentName,
DocumentUrlPath, NodeAliasPath, NodeID, NodeChildNodesCount,
NodeClassID, NodeLevel, NodeLinkedNodeID, NodeParentID, SiteName,
NodeACLID, NodeSiteID, NodeOwner, NodeOrder, NodeName,
DocumentSitemapSettings, NodeOrder AS CMS_O1, ROW_NUMBER() OVER (ORDER
BY DocumentName) AS CMS_SRN, 1 AS CMS_SN, 'cms.document.nmi.home' AS
CMS_T FROM View_NMI_Home_Joined WHERE NodeSiteID = #NodeSiteID AND
(DocumentMenuItemHideInNavigation = 0) AND (Published = #Published AND
NodeLevel <= #NodeLevel AND DocumentCulture = #DocumentCulture) ) AS
SubData ORDER BY CMS_O1, CMS_SRN, CMS_SN
Caused exception: Conversion failed when converting from a character
string to uniqueidentifier. ]
CMS.DataEngine.AbstractDataConnection.HandleError(String queryText,
Exception ex) +282
CMS.DataEngine.AbstractDataConnection.ExecuteQuery(String queryText,
QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean
requiresTransaction) +342
CMS.DataEngine.GeneralConnection.RunQuery(QueryParameters query) +384
CMS.DataEngine.GeneralConnection.ExecuteQueryInternal(QueryParameters
query) +458 CMS.DataEngine.DataQueryBase1.GetDataFromDB() +149
CMS.DataEngine.DataQueryBase1.GetData() +120
CMS.DataEngine.DataQueryBase1.get_Result() +106
CMS.DocumentEngine.DocumentQueryProperties.FilterResultsByPermissions(IDataQuery
query, Int32& totalRecords) +2128
CMS.DocumentEngine.MultiDocumentQueryBase3.GetResults(IDataQuery
query, Int32& totalRecords) +54
CMS.DataEngine.MultiQueryBase2.GetDataFromDB() +60
CMS.DataEngine.DataQueryBase1.GetData() +120
CMS.DataEngine.DataQueryBase`1.get_Result() +106
CMS.Controls.CMSAbstractMenuProperties.GetMenuItems(String
resolvedPath, Boolean siteMap) +910
CMS.Controls.CMSAbstractMenuProperties.GetDataSource(Boolean siteMap)
+839 CMS.Controls.CMSListMenu.ReloadData(Boolean forceLoad) +202 CMS.Controls.CMSListMenu.InitControl(Boolean loadPhase) +162
CMS.Controls.CMSListMenu.OnLoad(EventArgs e) +500
System.Web.UI.Control.LoadRecursive() +68
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Control.LoadRecursive() +162
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+3811
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.7.2106.0
I compared what I thought was the table giving the error with the Document Types cms.document.nmi.home which inherits from cms.document.nmi.page and the conflicting data type 'MenuItemTeaserImage' and saw the following:
And the field type for the same data type in kentico admin is as follows:
https://snag.gy/ULS5Iz.jpg
How do I go about remedying this error? Thx
Have you've made sure you've run the SQL scripts after the code upgrade (If you've done the upgrade manually)?
https://docs.kentico.com/k8/installation/upgrading-kentico-7-to-8/upgrading-kentico-manually
Open the upgrade_8_0.sql script from the SQL directory in the upgrade installation folder.
Have you upgraded directly to Kentico 8.2? or is this the 8.0 version? If you do have you made sure the Site started between every upgrade? This will make sure all the DB updages are processed
The problem was caused by a custom page type NMI_Page, which had a MenuItemTeaserImage column. This column has exactly the same name as the MenuItemTeaserImage column in a different page type, but different type, which causes a conflict.
Using same field names in different page types is not recommended, so I used the page type name as a prefix for the field names.
I renamed the MenuItemTeaserImage field in the NMI_Page document type to NMI_PageMenuItemTeaserImage (and changed this name in all the transformations too).
My guess is that the cause may have been a change in the Page (menu item) page type. You're inheriting from this in you NMI_Page and perhaps the upgrade SQL did not deal with this effectively. What you've done above clearly worked, but I'm curious if you could have broken the inheritance and fixed your teaser field?
When I generate a table with field LocalDate, it will be mandatory.
#Column(name = "supported_date", nullable = false)
private LocalDate supportedDate;
I don't understand this rule.
It's right there in the #Column annotation: nullable = false means that the column is not nullable, which means that it cannot contain null values, which means that the column is required.
I am trying to populate a grid that encompasses two different tables. So I need:
1) Join functionality between the two tables.
2) Skip/Take to limit results.
3) Total count of rows in tables
I want to accomplish it using SqlExpression since it seems to be most supported in ServiceStack.OrmLite. However, when I do a Skip and Take, it returns "ORA-00918: column ambiguously defined" since the two tables have some columns with the same name.
The code is as follows:
var dbCustomersQuery2 = db.From<USER>()
.LeftJoin<USER, USERPROFILE>((user, profile) => user.Id == profile.USER_ID)
.Where<USER>(user => user.USERNAME == "sangee.ram")
.Where<USERPROFILE>(profile => profile.PROFILEID == 442);
var result = db.Select<ViewModel>(dbCustomersQuery2.Skip(1).Take(5));
Here is the stack trace:
at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
at Oracle.DataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at ServiceStack.OrmLite.OrmLiteCommand.ExecuteReader()
at ServiceStack.OrmLite.OrmLiteReadCommandExtensions.ExecReader(IDbCommand dbCmd, String sql)
at ServiceStack.OrmLite.OrmLiteResultsFilterExtensions.ConvertToList[T](IDbCommand dbCmd, String sql)
at ServiceStack.OrmLite.OrmLiteReadCommandExtensions.SqlList[T](IDbCommand dbCmd, String sql, Object anonType)
at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.<>c__DisplayClass10`1.<Select>b__f(IDbCommand dbCmd)
at ServiceStack.OrmLite.OrmLiteExecFilter.Exec[T](IDbConnection dbConn, Func`2 filter)
at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.Exec[T](IDbConnection dbConn, Func`2 filter)
at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.Select[T](IDbConnection dbConn, ISqlExpression expression, Object anonType)
at LO.Leads.UI.Tests.UserSecurityTests.CanQueryUserSecurity() in c:\Git\Cons.Orig.Lead\src\LO.Leads.UI\LO.Leads.UI.Tests\UserSecurityTests.cs:line 68
The first thing I noticed was that you included the skip and take inside the last select command, once I moved that out I no longer get the exception.
var userQuery = db.From<USER>()
.LeftJoin<USER, USERPROFILE>((user, profile) => user.Id == profile.USER_ID)
.Where<USER>(user => user.USERNAME == "sangee.ram")
.Where<USERPROFILE>(profile => Sql.In(profile.PROFILEID, new[] { 1, 441, 442, 452 }));
var result = db.Select<ViewModel>(userQuery)
.Skip(1)
.Take(2);
Assert.NotNull(result);
When I ran this test it returned 2 rows (2nd and 3rd) out of a possible 4 rows.
Hope this helps,
Stephen
I get this error when I click the Tools menu in CMS Desk in Kentico.
I am not sure where to start trouble shooting.
I have started down the path of copying the website down to run locally on my machine. Hoping that I might be able to get more information that way.
Ideas gratefully received.
Update - I have decided to re-install from scratch.
Update 2
I think the problem might have been that we a 3rd part payment gateway from Get Started installed that was not updated for version 7 of Kentico.
I was able to solve the initial error, which was due to a code folder being duplicated in the project.
However then next error is as follows;
Server Error in '/KenticoCMS7' Application.
--------------------------------------------------------------------------------
Invalid column name 'MenuItemGroup'.
Invalid column name 'MenuItemGroup'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'MenuItemGroup'.
Invalid column name 'MenuItemGroup'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Invalid column name 'MenuItemGroup'.Invalid column name 'MenuItemGroup'.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1753986 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5296058 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +558 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +59 System.Data.SqlClient.SqlDataReader.get_MetaData() +90 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +365 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +1379 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +175 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +134 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +140 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +316 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +88 CMS.DataProviderSQL.DataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction) +239[Exception: [DataConnection.HandleError]: Query: SELECT ClassName, DocumentCulture, DocumentModifiedWhen, DocumentMenuCaption, DocumentMenuClass, DocumentMenuClassHighLighted, DocumentMenuClassOver, DocumentShowInSiteMap, DocumentMenuItemHideInNavigation, DocumentMenuItemImage, DocumentMenuItemImageHighlighted, DocumentMenuItemImageOver, DocumentMenuItemInactive, DocumentMenuItemLeftImage, DocumentMenuItemLeftImageHighlighted, DocumentMenuItemLeftImageOver, DocumentMenuItemRightImage, DocumentMenuItemRightImageHighlighted, DocumentMenuItemRightImageOver, DocumentMenuJavascript, DocumentMenuRedirectUrl, DocumentMenuStyle, DocumentMenuStyleHighlighted, DocumentMenuStyleOver, DocumentName, DocumentUrlPath, NodeAliasPath, NodeID, NodeChildNodesCount, NodeClassID, NodeLevel, NodeLinkedNodeID, NodeParentID, SiteName, NodeACLID, NodeSiteID, NodeOwner, NodeOrder, NodeName, DocumentSitemapSettings FROM View_CONTENT_MenuItem_Joined WHERE (((((NodeSiteID = 1) AND (Published = 1)) AND (DocumentCulture = N'en-US')) AND (NodeLevel <= 2)) AND (((DocumentMenuItemHideInNavigation = 0)) AND (MenuItemGroup <> 'footer' OR MenuItemGroup IS NULL))) ORDER BY NodeLevel, NodeOrder, DocumentName: caused exception: Invalid column name 'MenuItemGroup'.Invalid column name 'MenuItemGroup'.] CMS.DataEngine.AbstractDataConnection.HandleError(String queryText, SqlException ex) +158 CMS.DataProviderSQL.DataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction) +294 CMS.DataEngine.AbstractDataConnection.CMS.SettingsProvider.IDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction) +52 CMS.DataEngine.GeneralConnection.RunQuery(QueryParameters query) +280 CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters query) +581 CMS.DataEngine.GeneralConnection.ExecuteQuery(String queryName, QueryDataParameters parameters, String where, String orderBy, Int32 topN, String columns) +321 CMS.DataEngine.GeneralConnection.ExecuteQuery(String queryName, QueryDataParameters parameters, String where, String orderBy, Int32 topN, String columns, Int32 offset, Int32 maxRecords, Int32& totalRecords) +116 CMS.DataEngine.ConnectionHelper.ExecuteQuery(String queryName, QueryDataParameters parameters, String where, String orderBy, Int32 topN, String columns, Int32 offset, Int32 maxRecords, Int32& totalRecords) +90 CMS.DocumentEngine.TreeProvider.ExecuteQuery(String queryName, QueryDataParameters parameters, String where, String orderBy, Int32 topN, String columns, Int32 offset, Int32 maxRecords, Int32& totalRecords) +137 CMS.DocumentEngine.TreeProvider.ExecuteQuery(String queryName, QueryDataParameters parameters, String where, String orderBy, Int32 topN, String columns) +73 CMS.DocumentEngine.TreeProvider.SelectNodes(NodeSelectionParameters parameters) +2631 CMS.DocumentEngine.TreeProvider.SelectNodes(String siteName, String aliasPath, String cultureCode, Boolean combineWithDefaultCulture, String classNames, String where, String orderBy, Int32 maxRelativeLevel, Boolean selectOnlyPublished, Int32 topN, String columns) +247 CMS.Controls.CMSAbstractMenuProperties.GetMenuItems(String resolvedPath, Boolean siteMap) +1568 CMS.Controls.CMSAbstractMenuProperties.GetDataSource(Boolean siteMap) +1168 CMS.Controls.CMSAbstractMenuProperties.GetDataSource() +46 CMS.Controls.CMSListMenu.ReloadData(Boolean forceLoad) +270 CMS.Controls.CMSListMenu.OnInit(EventArgs e) +160 System.Web.UI.Control.InitRecursive(Control namingContainer) +134 System.Web.UI.Control.InitRecursive(Control namingContainer) +290 System.Web.UI.Control.InitRecursive(Control namingContainer) +290 System.Web.UI.Control.InitRecursive(Control namingContainer) +290 System.Web.UI.Control.InitRecursive(Control namingContainer) +290 System.Web.UI.Control.InitRecursive(Control namingContainer) +290 System.Web.UI.Control.InitRecursive(Control namingContainer) +290 System.Web.UI.Control.InitRecursive(Control namingContainer) +290 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +489
Kentico support suggested
Does the error appear on some page using (either directly, or inherited) Hierarchical viewer web part? If so, could you please edit its properties and see the Where condition? Is there anything like “MenuItemGroup = ‘xxx’”? If so, can you delete it and see the difference?
Optionally, you could try going to Site Manager -> Development -> System tables -> Views and hit the refresh all views button or,
Site Manager -> Development -> Document types -> Page menu item type -> Fields and hit save to re-generate the schemas or,
apply the latest hotfix to refresh the whole DB and files.
I applied Hotfix 31 on top of 30, but it didnt help. I dont think I could get into the program to try the issues support talked about.
Update: I have removed the get started code, and established that I create a new site in my old install that will successfully import into a fresh Kentico install without damaging the Tools menu... now to try and get my real site exporting and importing without breaking ....
Hooray - yes it worked!
[Update]
I am no longer sure that this problem was due to the Get Started gateway not being for 7.0
The fact that I was able to export one of the sites cleanly does not mean that the problem was solved. I have continued the discussion
here
I started a new question because I thought I had solved the problem by exporting and importing. However now I realise that this only solves the problem for a site that has clean data. In retrospect I should have continued this question.
You have few options. Firstly you can try to examine the sql script of the plugin and try to reverse changes it made (and remove files that are part of the plugin). Secondly you can export your site and import it to the fresh instance.
Have you imported site or objects from some older Kentico versions? If so, it seems that while importing, the Page menu item document type was overwritten and the new field "MenuItemGroup" was removed. You can try adding a field with this name back to given document type.
I'm new to cassandra and hector so i'm trying to execute cql queries but the problem is that not all columns are of type string so how dow I execute the query "select * from users"?
My column family looks like this:
UPDATE COLUMN FAMILY users
WITH comparator = UTF8Type
AND key_validation_class=UTF8Type
AND column_metadata = [
{column_name: full_name, validation_class: UTF8Type}
{column_name: email, validation_class: UTF8Type}
{column_name: state, validation_class: UTF8Type, index_type: KEYS}
{column_name: gender, validation_class: UTF8Type}
{column_name: birth_year, validation_class: LongType, index_type: KEYS}
{column_name: education, validation_class: UTF8Type}
];
I use the following code to execute the query:
CqlQuery<String, String, String> cqlQuery = new CqlQuery<String, String, String>(Keyspace,stringSerializer,stringSerializer,stringSerializer);
cqlQuery.setQuery("select * from users");
QueryResult<CqlRows<String, String, String>> result = cqlQuery.execute();
if (result != null && result.get() != null) {
List<Row<String, String, String>> list = result.get().getList();
for (Row row : list) {
System.out.println(".");
List columns = row.getColumnSlice().getColumns();
for (Iterator iterator = columns.iterator(); iterator.hasNext();) {
HColumn column = (HColumn) iterator.next();
System.out.print(column.getName() + ":" + column.getValue()
+ "\t");
}
System.out.println("");
}
}
But because of the 'birth_year' column with validation class Long I can't get the value.
I get the following result assuming that there is only one record:
KEY:Carl birth_year: 'strange chars?' full_name:Carl Smith gender:M eduction:electrician state:LA
If I change my query to this:
CqlQuery<String, String, Long> cqlQuery = new CqlQuery<String, String, Long>
TutorialBase.tutorialKeyspace, stringSerializer, stringSerializer, longSerializer);
cqlQuery.setQuery("select birth_year from users");
Than it works.
So how can I do this with only one query and what if I have more datatypes like booleans and floats in the rows of a column family?
You specify the value type as String in the CqlRows, so every value is expected to be a string. Because you want to mix Value types, you should keep the column metadata, but also specify the default validation class as BytesType in the schema and then use ByteBuffer as the type in CqlRows:
QueryResult<CqlRows<String, String, ByteBuffer>> result = cqlQuery.execute();
Then, when processing the values, you will have to convert to the appropriate type, and instead of iterating through the columns, you will probably get the specific column by name:
ColumnSlice<String, ByteBuffer> slice = row.getColumnSlice();
HColumn<String,ByteBuffer> col = slice.getColumnByName("birth_year");
System.out.println(" birth_year: " + col.getValue().getLong());
Of course, Strings have to be handled differently, using java.nio.charset.Charset:
Charset.defaultCharset().decode(col.getValue()).toString()
You can determine types from the Column meta-data, but I've only done this via the Thrift API (see ColumnDef), so not sure how to do it via Hector API. But HColumn does provide a getValueSerializer() method, so that could be a start.